package cn.getech.data.development.service.impl;

import cn.getech.data.development.config.properties.BdpJobConfig;
import cn.getech.data.development.config.properties.DataDevelopmentConfig;
import cn.getech.data.development.constant.*;
import cn.getech.data.development.controller.offline.HiveTableDdl;
import cn.getech.data.development.dto.*;
import cn.getech.data.development.entity.*;
import cn.getech.data.development.entity.flink.*;
import cn.getech.data.development.entity.permission.SysRoleDataPermission;
import cn.getech.data.development.entity.permission.SysRoleDataPermissionExample;
import cn.getech.data.development.entity.permission.SysTenantDataPermission;
import cn.getech.data.development.mapper.*;
import cn.getech.data.development.mapper.flink.*;
import cn.getech.data.development.mapper.permission.SysRoleDataPermissionMapper;
import cn.getech.data.development.model.dto.*;
import cn.getech.data.development.model.qo.UploadVersionLogQO;
import cn.getech.data.development.model.vo.*;
import cn.getech.data.development.service.*;
import cn.getech.data.development.utils.CompressUtil;
import cn.getech.data.development.utils.HdfsUtil;
import cn.getech.data.development.utils.HiveTableUtil;
import cn.getech.data.development.utils.TimeUtil;
import cn.getech.data.development.utils.kafka.LocalKafkaUtil;
import cn.getech.data.development.utils.spring.SpringContextUtil;
import cn.getech.data.intelligence.common.exception.RRException;
import cn.getech.data.intelligence.common.utils.PageUtils;
import cn.getech.data.intelligence.common.utils.PojoUtils;
import cn.getech.data.intelligence.common.utils.QueryBean;
import cn.getech.data.intelligence.common.utils.R;
import cn.getech.system.center.service.SysUserService;
import cn.getech.system.center.utils.ShiroUtils;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.fs.FSDataInputStream;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * <p>
 * 上传版本包记录 服务实现类
 * </p>
 *
 * @author hujz
 * @since 2020-07-03
 */
@Slf4j
@Service
public class UploadVersionLogServiceImpl extends ServiceImpl<UploadVersionLogMapper, UploadVersionLog> implements UploadVersionLogService {

    @Autowired
    private UploadVersionLogMapper uploadVersionLogMapper;
    @Autowired
    private BdpJobConfig bdpJobConfig;
    @Autowired
    private JobRunUdfMapper jobRunUdfMapper;
    @Autowired
    private ConfConnectMapper confConnectMapper;
    @Autowired
    private ProcConnectMapper procConnectMapper;
    @Autowired
    private TableInfoMapper tableInfoMapper;
    @Autowired
    private BdpRealTableInfoMapper bdpRealTableInfoMapper;
    @Autowired
    private ProcTableMapper procTableMapper;
    @Autowired
    private ProcUserMapper procUserMapper;
    @Autowired
    private TableFieldInfoMapper tableFieldInfoMapper;
    @Autowired
    private BdpRealTableFieldMapper realTableFieldMapper;
    @Autowired
    private WorkMenuMapper workMenuMapper;
    @Autowired
    private RealTimeTaskMenuMapper realTimeTaskMenuMapper;
    @Autowired
    private RealTimeTaskMapper realTimeTaskMapper;
    @Autowired
    private FlinkTaskNodeMapper flinkTaskNodeMapper;
    @Autowired
    private FlinkNodeFieldMapper flinkNodeFieldMapper;
    @Autowired
    private FlinkNodeUnionMapper flinkNodeUnionMapper;
    @Autowired
    private BdpRealTaskAlarmObjectMapper realTaskAlarmObjectMapper;
    @Autowired
    private IBdpVersionService iBdpVersionService;
    @Autowired
    private IWorkMenuService iWorkMenuService;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private WorkMenuJobRelMapper workMenuJobRelMapper;
    @Autowired
    private IWorkMenuJobRelService iWorkMenuJobRelService;
    @Autowired
    private JobInfoMapper jobInfoMapper;
    @Autowired
    private JobNodeInfoMapper jobNodeInfoMapper;
    @Autowired
    private JobNodeInfoService jobNodeInfoService;
    @Autowired
    private JobLinkMapper jobLinkMapper;
    @Autowired
    private SapConnectFieldMapper sapConnectFieldMapper;
    @Autowired
    private JobNodeConfMapper jobNodeConfMapper;
    @Autowired
    private WorkFlowDepMapper workFlowDepMapper;
    @Autowired
    private VersionChangeLogMapper versionChangeLogMapper;
    @Autowired
    private JobNodeLayConfigMapper jobNodeLayConfigMapper;
    @Autowired
    private ConnectFieldInfoMapper connectFieldInfoMapper;
    @Autowired
    private BdpUdfJarInfoMapper bdpUdfJarInfoMapper;
    @Autowired
    private BdpVersionMapper bdpVersionMapper;
    @Autowired
    private BdpVersionProcRelMapper bdpVersionProcRelMapper;
    @Autowired
    private ConnectFieldInfoService connectFieldInfoService;
    @Autowired
    private DataDevelopmentConfig hiveConfig;
    @Autowired
    private TableInfoService tableInfoService;
    @Autowired
    private BdpRealTableInfoService realTableInfoService;
    @Autowired
    private TableFieldInfoService tableFieldInfoService;
    @Autowired
    private DataDevelopmentConfig dataDevelopmentConfig;
    @Autowired
    private AlarmObjectService alarmObjectService;
    @Autowired
    FlinkTaskNodeService flinkTaskNodeService;
    @Autowired
    private UploadVersionConnectResultLogMapper uploadVersionConnectResultLogMapper;
    @Autowired
    private UploadVersionTableResultLogMapper uploadVersionTableResultLogMapper;
    @Autowired
    private UploadVersionWorkflowResultLogMapper uploadVersionWorkflowResultLogMapper;
    @Autowired
    private DataPermissionService dataPermissionService;
    @Autowired
    private SysRoleDataPermissionMapper sysRoleDataPermissionMapper;
    @Autowired
    private RangerDataService rangerDataService;
    @Autowired
    private BeanDataChangeService beanDataChangeService;
    @Autowired
    private UploadVersionAllJsonCheackLogService uploadVersionAllJsonCheackLogService;
    @Autowired
    private BussessConfigMapper bussessConfigMapper;
    @Autowired
    private TableRegisterService tableRegisterService;

    @Autowired
    RealTimeTaskMenuService realTimeTaskMenuService;
    @Autowired
    RealTimeTaskService realTimeTaskService;

    @Value("${spring.kafka.bootstrap-servers:}")
    private String kafkaUrl;


    @Override
    public PageUtils page(UploadVersionLogQO uploadVersionLogQO) {
        IPage<UploadVersionLog> page = uploadVersionLogMapper.selectListPage((Page<UploadVersionLog>) new QueryBean<UploadVersionLog, UploadVersionLogQO>().getPage(uploadVersionLogQO), uploadVersionLogQO);
        return new PageUtils(page);
    }

    @Override
    public UploadVersionLogDto getUploadLog(String zipPathName) {
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null != uploadVersionLog) {
            //查询对应的数据是否满足全部完成
            Integer isFinsh = 1;
            Long failCountSum = 0L;
            if (!Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.FAIL.getId())
                    && !Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.SUCCESS.getId())) {
                List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper.selectList(new QueryWrapper<UploadVersionConnectResultLog>()
                        .eq("upload_version_log_id", uploadVersionLog.getId()));
                if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)) {
                    long count = uploadVersionConnectResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())).count();
                    if (count > 0) {
                        isFinsh = 0;
                    }
                    long failCount = uploadVersionConnectResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
                    failCountSum = failCountSum + failCount;
                }
                List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>()
                        .eq("upload_version_log_id", uploadVersionLog.getId()));
                if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)) {
                    long count = uploadVersionTableResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())).count();
                    if (count > 0) {
                        isFinsh = 0;
                    }
                    long failCount = uploadVersionTableResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
                    failCountSum = failCountSum + failCount;
                }
                List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                        .eq("upload_version_log_id", uploadVersionLog.getId()).in("import_type", 0, 1, 3));
                if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                    long count = uploadVersionWorkflowResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())).count();
                    if (count > 0) {
                        isFinsh = 0;
                    }
                    long failCount = uploadVersionWorkflowResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
                    failCountSum = failCountSum + failCount;
                }
            }
            UploadVersionLogDto uploadVersionLogDto = new UploadVersionLogDto();
            BeanUtils.copyProperties(uploadVersionLog, uploadVersionLogDto);
            uploadVersionLogDto.setIsFinsh(isFinsh);
            uploadVersionLogDto.setFailCount(failCountSum);
            return uploadVersionLogDto;
        }
        return null;

    }

    @Override
    public UploadVersionLogDto uploadVersionZip(Integer procId, String zipPathName, MultipartFile multipartFile) {

        if (StringUtils.isNotEmpty(zipPathName)) {
            UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
            if (null != uploadVersionLog) {
                //如果是确认导入过，则不能重复导入文件
                if (!Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())) {
                    throw new RRException("不能重新上传版本包！");
                }
                //删除版本上传记录和对应的资源版本包
                uploadVersionLogMapper.deleteById(uploadVersionLog.getId());
                //删除hdfs上的文件
                deleteUploadVersion(uploadVersionLog);
                //删除掉对应的检测文件
                uploadVersionAllJsonCheackLogService.remove(new QueryWrapper<UploadVersionAllJsonCheackLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
            }
        }

        String jarName = UUID.randomUUID().toString().replace("-", "");
        String upZipVersionName = "";
        String upZipVersionNum = "";
        String upZipHost = "";
        String upZipEnv = "";
        Integer olderProcId = 0;
        String originalFilename = multipartFile.getOriginalFilename();
//        try {
//            originalFilename = new String(multipartFile.getOriginalFilename().getBytes(),"utf-8");
//        } catch (UnsupportedEncodingException e) {
//            throw new RRException("获取文件名异常！error:"+e.getMessage());
//        }
        if (StringUtils.isEmpty(originalFilename)) {
            throw new RRException("获取文件名异常！");
        }
        int index = originalFilename.lastIndexOf(".");
        String olderName = originalFilename.substring(0, index);
        String zipPreff = originalFilename.substring(index + 1);

        //将multipartFile对应的zip解析出来
        List<FileModelDto> unzipList = CompressUtil.unzip(multipartFile);
        VersionZipDto versionZipDto = null;
        if (CollectionUtil.isNotEmpty(unzipList)) {
            versionZipDto = changeZip(unzipList, Boolean.TRUE);
        }
        if (null == versionZipDto) {
            throw new RRException("上传的版本包解析json异常！");
        }
        upZipVersionName = versionZipDto.getVersionName();
        upZipVersionNum = versionZipDto.getVersionNum();
        upZipHost = versionZipDto.getZipHost();
        upZipEnv = versionZipDto.getZipEnv();
        olderProcId = versionZipDto.getProcId();

        //上传文件，因为后期可能还包含udf函数，必须上传文件并且存起来
        HdfsUtil hdfsUtil = null;
        try {
            //将解析file文件上传到hdfs保存起来--先生成zip文件，再上传
            hdfsUtil = new HdfsUtil(bdpJobConfig);
            for (FileModelDto fileModelDto : unzipList) {
                String fileName = fileModelDto.getFileName();
                if (StringUtils.isNotEmpty(fileName) && Objects.equals(".json", fileName.substring(fileName.lastIndexOf(".")))) {
                    String uploadPath = String.format("%s/%s/%s", bdpJobConfig.getVersion(), procId, jarName + ".json");
                    hdfsUtil.writeFile(versionZipDto.getAllDataJson().getBytes("utf-8"), uploadPath);
                } else {
                    String uploadPath = String.format("%s/%s/%s", bdpJobConfig.getVersion(), procId, jarName + ".jar");
                    hdfsUtil.writeFile(CompressUtil.toByteArray(fileModelDto.getFileInputstream()), uploadPath);
                }
            }
            hdfsUtil.close();
        } catch (Exception e) {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
            log.error("上传的版本转换成文件异常！error:{}", e.getMessage());
            throw new RRException("上传的版本转换成文件异常！");
        }

        UploadVersionLog uploadVersionLog = new UploadVersionLog();
        uploadVersionLog.setUpZipVersionName(upZipVersionName);
        uploadVersionLog.setUpZipVersionNum(upZipVersionNum);
        uploadVersionLog.setOlderProcId(olderProcId);
        uploadVersionLog.setUpZipHost(upZipHost);
        uploadVersionLog.setUpZipEnv(upZipEnv);
        uploadVersionLog.setUpZipTime(LocalDateTime.now());
        uploadVersionLog.setUpZipType(0);
        uploadVersionLog.setUpZipStatus(2);
        //标识
        uploadVersionLog.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
        uploadVersionLog.setProcId(procId);
        uploadVersionLog.setZipPathName(jarName);
        uploadVersionLog.setZipOlderName(olderName);
        uploadVersionLog.setZipVersionPreffix(zipPreff);
//        uploadVersionLog.setImportAllJson(versionZipDto.getAllDataJson());//暂时去掉这个参数。太大了不利于表存储
        uploadVersionLog.setImportStep(ImportStepEnum.UPLOAD_ED.getId());
        uploadVersionLogMapper.insert(uploadVersionLog);

        UploadVersionLogDto uploadVersionLogDto = new UploadVersionLogDto();
        BeanUtils.copyProperties(uploadVersionLog, uploadVersionLogDto);
        return uploadVersionLogDto;
    }

    private boolean cheackVersion(UploadVersionLog uploadVersionLog) {
        if (null == uploadVersionLog) {
            return false;
        }
        //查询到对应的连接中是否有数据，如果有，则不能重复导入
        List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper.selectList(new QueryWrapper<UploadVersionConnectResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)) {
            return true;
        }
        //查询到对应的仓库中是否有数据。如果有，则不能重复导入
        List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)) {
            return true;
        }
        //查询到对应的工作流是否有数据。如果有，则不能重复导入
        List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
            return true;
        }
        return false;
    }

    private void deleteUploadVersion(UploadVersionLog uploadVersionLog) {
        HdfsUtil hdfsUtil = null;
        try {
            String uploadPath = String.format("%s/%s/%s", bdpJobConfig.getVersion(), uploadVersionLog.getProcId(), uploadVersionLog.getZipPathName() + ".json");
            hdfsUtil = new HdfsUtil(bdpJobConfig);
            hdfsUtil.delete(uploadPath);
            hdfsUtil.close();
        } catch (Exception e) {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
            log.error("删除版本资源文件:{}异常！error:{}", uploadVersionLog.getZipPathName(), e.getMessage());
            throw new RRException("删除版本资源文件:" + uploadVersionLog.getZipPathName() + "异常！");
        }
    }


    private VersionZipDto changeZip(List<FileModelDto> unzipList, Boolean aFalse) {
        for (FileModelDto fileModelDto : unzipList) {
            String fileName = fileModelDto.getFileName();
            if (StringUtils.isNotEmpty(fileName) && Objects.equals(".json", fileName.substring(fileName.lastIndexOf(".")))) {
                //json文件。解析对应的这个文件的资源
                String dataJson = CompressUtil.readJsonFile(fileModelDto.getFileInputstream());
                if (StringUtils.isEmpty(dataJson)) {
                    throw new RRException("上传的版本包资源文件不正确！");
                }
                //将对应的json文件解析出来
                VersionZipDto versionZipDto = beanDataChangeService.changeJsonToModel(dataJson, aFalse);
                if (null != versionZipDto) {
                    versionZipDto.setAllDataJson(dataJson);
                    return versionZipDto;
                } else {
                    log.error("上传的版本包解析json异常！");
                    throw new RRException("上传的版本包解析json异常！");
                }
            }
            if (StringUtils.isNotEmpty(fileName) && Objects.equals(".jar", fileName.substring(fileName.lastIndexOf(".")))) {
                //udf函数文件
            }
        }
        return null;
    }


    @Override
    public void updateRole(UploadVersionUpdateRoleVO uploadVersionUpdateRoleVO) {
        if (null == uploadVersionUpdateRoleVO || StringUtils.isEmpty(uploadVersionUpdateRoleVO.getZipPathName())) {
            throw new RRException("上传的文件必须传递！");
        }
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", uploadVersionUpdateRoleVO.getZipPathName()));
        if (null == uploadVersionLog) {
            throw new RRException("上传的文件不存在！");
        }
        if (!Objects.equals(uploadVersionUpdateRoleVO.getImportChangeRole(), uploadVersionLog.getImportChangeRole())) {
            if (!Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())) {
                throw new RRException("不能修改角色信息！");
            }
            uploadVersionLog.setImportChangeRole(uploadVersionUpdateRoleVO.getImportChangeRole());
            uploadVersionLogMapper.updateById(uploadVersionLog);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cancelupload(String zipPathName) {
        if (StringUtils.isNotEmpty(zipPathName)) {
            UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
            if (null != uploadVersionLog) {
                if (!Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.NEED_IMPORT.getId())) {
                    throw new RRException("版本文件不能取消！");
                }
                //删除版本上传记录和对应的资源版本包
                uploadVersionLogMapper.deleteById(uploadVersionLog.getId());
                //删除对应的检测文件
                uploadVersionAllJsonCheackLogService.remove(new QueryWrapper<UploadVersionAllJsonCheackLog>().eq("upload_version_log_id", uploadVersionLog.getId()));

                //删除hdfs上的文件
                deleteUploadVersion(uploadVersionLog);
            }
        }
    }

    @Override
    public void finsh(String zipPathName) {
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        UploadVersionLogDto uploadLog = getUploadLog(zipPathName);
        if (null == uploadLog) {
            throw new RRException("版本包资源不存在！");
        }
        if (Objects.equals(uploadLog.getIsFinsh(), 0)) {
            throw new RRException("正在导入中，暂时还不能完成，请稍后重试！");
        }
        if (Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.FAIL.getId())
                || Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.SUCCESS.getId())) {
            //已经完成过
            return;
        }
        //验证当前版本前的记录是否都完成了。针对于相同的工程
        List<UploadVersionLog> olderUploadVersionLogs = uploadVersionLogMapper.selectList(new QueryWrapper<UploadVersionLog>()
                .eq("proc_id", uploadVersionLog.getProcId())
                .lt("up_zip_time", uploadVersionLog.getUpZipTime())
                .in("import_status", 2, 3));
        if (CollectionUtil.isNotEmpty(olderUploadVersionLogs)) {
            throw new RRException("请完成前面的导入版本记录！");
        }
//        //验证之前是否有未点击完成的（如果有，则不能点击当初完成）。针对于相同的工程
//        List<UploadVersionLog> uploadVersionLogs = uploadVersionLogMapper.selectList(new QueryWrapper<UploadVersionLog>()
//                .eq("proc_id", uploadVersionLog.getProcId())
//                .gt("up_zip_time", uploadVersionLog.getUpZipTime())
//                .in("import_status", 0, 1));
//        if (CollectionUtil.isNotEmpty(uploadVersionLogs)) {
//            throw new RRException("请完成前面的导入版本记录！");
//        }
        Integer importStatus = ImportStatusEnum.SUCCESS.getId();
        if (uploadLog.getFailCount() > 0) {
            importStatus = ImportStatusEnum.FAIL.getId();
        }
        uploadVersionLog.setImportStatus(importStatus);
        uploadVersionLogMapper.updateById(uploadVersionLog);
    }

    @Override
    public UploadVersionCheckResultLogDto fileCheck(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }

        List<UploadVersionAllJsonCheackLog> uploadVersionAllJsonCheackLogs = uploadVersionAllJsonCheackLogService.list(new QueryWrapper<UploadVersionAllJsonCheackLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        //解析版本包中所有的数据
        List<UploadVersionAllJsonCheackLogDto> listRest = new ArrayList<>();
        if (CollectionUtil.isEmpty(uploadVersionAllJsonCheackLogs)) {
            VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
            if (null == versionZipDto) {
                throw new RRException("版本包文件格式不正确！");
            }
            //数据源连接
            List<ConfConnectAndConfigDto> connectList = versionZipDto.getConnectList();
            if (CollectionUtil.isNotEmpty(connectList)) {
                checkConnects(connectList, listRest, uploadVersionLog.getId());
            }
            //数据仓库
            List<TableInfoAndFieldDto> tableList = versionZipDto.getTableList();
            if (CollectionUtil.isNotEmpty(tableList)) {
                checkTables(tableList, listRest, uploadVersionLog.getId());
            }
            //实时表
            List<RealTableInfoAndFieldDto> realTableList = versionZipDto.getRealTableList();
            if (CollectionUtil.isNotEmpty(realTableList)) {
                checkRealTables(realTableList, listRest, uploadVersionLog.getId());
            }
            //工作流
            List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
            if (CollectionUtil.isNotEmpty(workMenuList)) {
                checkWorkflows(versionZipDto, listRest, uploadVersionLog.getId(), uploadVersionLog.getProcId());
                //挑选出来所有的工作流依赖
                List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
                filterAllWorkFlowNameAndLayName(workMenuList, allWorkFlowNames, Boolean.TRUE, Boolean.FALSE, null, Boolean.FALSE);
                if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
                    for (VersionWorkflowDto allWorkFlowName : allWorkFlowNames) {
                        addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 5, 0, null, listRest, uploadVersionLog.getId());
                    }
                }
            }
            //实时任务
            List<RealTimeTaskMenuAndTaskDto> realWorkMenuList = versionZipDto.getRealWorkMenuList();
            if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
                checkRealWorkflows(versionZipDto, listRest, uploadVersionLog.getId(), uploadVersionLog.getProcId());
            }
            if (CollectionUtil.isEmpty(listRest)) {
                uploadVersionLog.setImportStep(ImportStepEnum.IMPORT_WORKFLOW_ED.getId());
                uploadVersionLog.setUpZipStatus(0);
                uploadVersionLog.setImportStatus(ImportStatusEnum.SUCCESS.getId());
                uploadVersionLogMapper.updateById(uploadVersionLog);
                return null;
            }
            //批量保存进去
            List<UploadVersionAllJsonCheackLog> uploadVersionAllJsonCheackLogs1 = PojoUtils.listConvert(UploadVersionAllJsonCheackLog.class, listRest);
            uploadVersionAllJsonCheackLogService.saveBatch(uploadVersionAllJsonCheackLogs1);
            listRest.clear();
            listRest.addAll(PojoUtils.listConvert(UploadVersionAllJsonCheackLogDto.class, uploadVersionAllJsonCheackLogs1));

        } else {
            listRest.addAll(PojoUtils.listConvert(UploadVersionAllJsonCheackLogDto.class, uploadVersionAllJsonCheackLogs));
        }

        Long failCount = listRest.stream().filter(o -> Objects.equals(o.getCheackStatus(), 1)).count();
        UploadVersionCheckResultLogDto uploadVersionCheckResultLogDto = new UploadVersionCheckResultLogDto();
        uploadVersionCheckResultLogDto.setSumCount(listRest.size());
        uploadVersionCheckResultLogDto.setSuccessCount(listRest.size() - failCount.intValue());
        uploadVersionCheckResultLogDto.setFailCount(failCount.intValue());
        uploadVersionCheckResultLogDto.setAllCheckResults(listRest);

//        //改变流程状态
//        Integer importStep = uploadVersionLog.getImportStep();
//        if(Objects.equals(importStep,ImportStepEnum.CHECK_ING.getId()) || Objects.equals(importStep,ImportStepEnum.UPLOAD_ED.getId())){
//            uploadVersionLog.setImportStep(ImportStepEnum.CHECK_ED.getId());
//            uploadVersionLogMapper.updateById(uploadVersionLog);
//        }
        return uploadVersionCheckResultLogDto;
    }

    @Override
    public void reCheack(Long cheackLogId) {
        //重试检测
        UploadVersionAllJsonCheackLog uploadVersionAllJsonCheackLog = uploadVersionAllJsonCheackLogService.getById(cheackLogId);
        if (null == uploadVersionAllJsonCheackLog) {
            throw new RRException("重试的记录不存在！");
        }
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectById(uploadVersionAllJsonCheackLog.getUploadVersionLogId());
        if (null == uploadVersionLog) {
            throw new RRException("重试的资源文件不存在！");
        }
        //只要点击过确定或者完成按钮，则不能进行重试
        Integer isFinsh = uploadVersionLog.getImportStatus();
        Integer isSure = 0;
        StringBuilder msg = new StringBuilder();
        if (Objects.equals(isFinsh, ImportStatusEnum.FAIL.getId()) || Objects.equals(isFinsh, ImportStatusEnum.SUCCESS.getId())) {
            msg.append("流程已完成");
        }
//        if(Objects.equals(uploadVersionLog.getImportConnect(),1)){
//            List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper.selectList(new QueryWrapper<UploadVersionConnectResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
//            if(CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)){
//                isSure = 1;
//                if(msg.length() > 0){
//                    msg.append(",");
//                }
//                msg.append("数据源已确认导入");
//            }
//        }
//        if(Objects.equals(uploadVersionLog.getImportTable(),1)){
//            List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
//            if(CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)){
//                isSure = 1;
//                if(msg.length() > 0){
//                    msg.append(",");
//                }
//                msg.append("仓库表已确认导入");
//            }
//        }
        if (Objects.equals(uploadVersionLog.getImportWorkflow(), 1)) {
            List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
            if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                isSure = 1;
                if (msg.length() > 0) {
                    msg.append(",");
                }
                msg.append("工作流已确认导入");
            }
        }
        if (Objects.equals(1, isSure)
                || Objects.equals(isFinsh, ImportStatusEnum.FAIL.getId())
                || Objects.equals(isFinsh, ImportStatusEnum.SUCCESS.getId())) {
            throw new RRException(msg.toString() + "。检测不能重试！");
        }
        //检测这个文件
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), uploadVersionLog.getZipPathName(), uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        //只能检测工作流下的节点的配置
        List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            if (Objects.equals(uploadVersionAllJsonCheackLog.getCheackType(), 4)) {
                //挑选出来所有的工作流
                List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
                filterAllWorkFlowNameAndLayName(workMenuList, allWorkFlowNames, Boolean.FALSE, Boolean.TRUE, null, Boolean.FALSE);
                if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
                    //检测对应的工作流下的每一个节点的配置
                    VersionWorkflowDto versionWorkflowDto = allWorkFlowNames.stream().filter(o -> Objects.equals(o.getName(), uploadVersionAllJsonCheackLog.getCheackName())).findAny().orElse(null);
                    WorkMenuAndLayDto workMenuAndLayDto = workMenuList.stream().filter(o -> Objects.equals(o.getId(), versionWorkflowDto.getOlderId())).findAny().orElse(null);
                    List<UploadVersionAllJsonCheackLogDto> listRest = new ArrayList<>();
                    checkJobNodes(versionZipDto, workMenuAndLayDto, versionWorkflowDto, listRest, uploadVersionLog.getId(), uploadVersionLog.getProcId());
                    if (CollectionUtil.isNotEmpty(listRest)) {
                        Boolean flage = Boolean.FALSE;
                        String msg1 = null;
                        for (UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto : listRest) {
                            if (Objects.equals(uploadVersionAllJsonCheackLogDto.getCheackStatus(), ImportStatusEnum.FAIL.getId())) {
                                flage = Boolean.TRUE;
                                msg1 = uploadVersionAllJsonCheackLogDto.getRestMsgList();
                                break;
                            }
                        }
                        if (flage) {
                            uploadVersionAllJsonCheackLogService.updateStatusAndMsgById(uploadVersionAllJsonCheackLog.getId(), ImportStatusEnum.FAIL.getId(), msg1);
                            throw new RRException("重试失败，请查看原因！");
                        }
                    }
                }
            }
        }
        List<RealTimeTaskMenuAndTaskDto> realWorkMenuList = versionZipDto.getRealWorkMenuList();
        if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
            if (Objects.equals(uploadVersionAllJsonCheackLog.getCheackType(), 7)) {
                //挑选出来所有的实时任务
                List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
                filterAllRealWorkFlowName(realWorkMenuList, allWorkFlowNames, null, Boolean.FALSE);
                if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
                    //检测对应的实时任务下的每一个节点的配置
                    VersionWorkflowDto versionWorkflowDto = allWorkFlowNames.stream().filter(o -> Objects.equals(o.getName(), uploadVersionAllJsonCheackLog.getCheackName())).findAny().orElse(null);
                    RealTimeTaskMenuAndTaskDto workMenuAndLayDto = realWorkMenuList.stream().filter(o -> Objects.equals(o.getId(), versionWorkflowDto.getOlderId())).findAny().orElse(null);
                    List<UploadVersionAllJsonCheackLogDto> listRest = new ArrayList<>();
                    checkRealTaskNodes(versionZipDto, workMenuAndLayDto, versionWorkflowDto, listRest, uploadVersionLog.getId(), uploadVersionLog.getProcId());
                    if (CollectionUtil.isNotEmpty(listRest)) {
                        Boolean flage = Boolean.FALSE;
                        String msg1 = null;
                        for (UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto : listRest) {
                            if (Objects.equals(uploadVersionAllJsonCheackLogDto.getCheackStatus(), ImportStatusEnum.FAIL.getId())) {
                                flage = Boolean.TRUE;
                                msg1 = uploadVersionAllJsonCheackLogDto.getRestMsgList();
                                break;
                            }
                        }
                        if (flage) {
                            uploadVersionAllJsonCheackLogService.updateStatusAndMsgById(uploadVersionAllJsonCheackLog.getId(), ImportStatusEnum.FAIL.getId(), msg1);
                            throw new RRException("重试失败，请查看原因！");
                        }
                    }
                }
            }
        }
        //改变对应的状态
        uploadVersionAllJsonCheackLogService.updateStatusAndMsgById(uploadVersionAllJsonCheackLog.getId(), ImportStatusEnum.SUCCESS.getId(), "");
    }

    @Override
    public UploadVersionConnectResultLogSumDto connectRests(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isEmpty(versionZipDto.getConnectList())) {
            uploadVersionLog.setImportConnect(1);
            uploadVersionLogMapper.updateById(uploadVersionLog);
            UploadVersionConnectResultLogSumDto uploadVersionConnectResultLogSumDto = new UploadVersionConnectResultLogSumDto();
            uploadVersionConnectResultLogSumDto.setSumCount(0);
            uploadVersionConnectResultLogSumDto.setSuccessCount(0);
            uploadVersionConnectResultLogSumDto.setFailCount(0);
            uploadVersionConnectResultLogSumDto.setImportStatus(ImportStatusEnum.SUCCESS.getId());
            return uploadVersionConnectResultLogSumDto;
        }
        List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper.selectList(new QueryWrapper<UploadVersionConnectResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        List<UploadVersionConnectResultLogDto> allCheckResults = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)) {
            allCheckResults.addAll(PojoUtils.listConvert(UploadVersionConnectResultLogDto.class, uploadVersionConnectResultLogs));
        } else {
            List<UploadVersionConnectResultLogDto> uploadVersionConnectResultLogDtos = analyConnect2Exit(versionZipDto.getConnectList(), uploadVersionLog.getId());
            if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogDtos)) {
                allCheckResults.addAll(uploadVersionConnectResultLogDtos);
            }
        }
        if (CollectionUtil.isNotEmpty(allCheckResults)) {
            Long failCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
            Long successCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.SUCCESS.getId())).count();
            Integer sumCount = allCheckResults.size();
            Integer importStatusSum = ImportStatusEnum.SUCCESS.getId();
            if (!Objects.equals(uploadVersionLog.getImportConnect(), 1)) {
                importStatusSum = ImportStatusEnum.NEED_IMPORT.getId();
            }

            UploadVersionConnectResultLogSumDto uploadVersionConnectResultLogSumDto = new UploadVersionConnectResultLogSumDto();
            uploadVersionConnectResultLogSumDto.setSumCount(sumCount);
            uploadVersionConnectResultLogSumDto.setSuccessCount(successCount.intValue());
            uploadVersionConnectResultLogSumDto.setFailCount(failCount.intValue());
            uploadVersionConnectResultLogSumDto.setImportStatus(importStatusSum);
            uploadVersionConnectResultLogSumDto.setAllCheckResults(allCheckResults);
            return uploadVersionConnectResultLogSumDto;
        }
        return null;
    }

    private List<UploadVersionConnectResultLogDto> analyConnect2Exit(List<ConfConnectAndConfigDto> connectList, Long uploadVersionLogId) {
        List<UploadVersionConnectResultLogDto> list = new ArrayList<>();
        Integer tenantId = ShiroUtils.getTenantId();
        for (ConfConnectAndConfigDto confConnectAndConfigDto : connectList) {
//            Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
            ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                            .eq("name", confConnectAndConfigDto.getName())
                    .eq("tenant_id",tenantId) //当前租户是否有重名的数据源
//                    .eq("create_per",userId)
//                    .eq("type_id",confConnectAndConfigDto.getTypeId())
            );
            Integer isExits = 0;
            UploadVersionConnectResultLogDto uploadVersionConnectResultLogDto = new UploadVersionConnectResultLogDto();
            uploadVersionConnectResultLogDto.setUploadVersionLogId(uploadVersionLogId);
            uploadVersionConnectResultLogDto.setConnectName(confConnectAndConfigDto.getName());
            uploadVersionConnectResultLogDto.setOlderConnectDataId(Long.valueOf(confConnectAndConfigDto.getId()));
            if (null != confConnect) {
                isExits = 1;
                uploadVersionConnectResultLogDto.setExitConnectId(Long.valueOf(confConnect.getId()));
            }
            uploadVersionConnectResultLogDto.setIsExit(isExits);
            uploadVersionConnectResultLogDto.setCreatePerName(confConnectAndConfigDto.getCreatePerName());
            uploadVersionConnectResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
            list.add(uploadVersionConnectResultLogDto);
        }
        return list;
    }

    @Override
    public void confirmImportConnects(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        if (Objects.equals(uploadVersionLog.getImportConnect(), 1)) {
            throw new RRException("已经确认导入过，则不能重复导入！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isNotEmpty(versionZipDto.getConnectList())) {
            List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper.selectList(new QueryWrapper<UploadVersionConnectResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
            if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)) {
                throw new RRException("已经确认导入过，则不能重复导入！");
            }
            //先备份，在导入
            backUps(uploadVersionLog);
            //将数据先放入记录表中
            List<UploadVersionConnectResultLogDto> uploadVersionConnectResultLogDtos = analyConnect2Exit(versionZipDto.getConnectList(), uploadVersionLog.getId());
            if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogDtos)) {
                uploadVersionConnectResultLogMapper.insertBatch(uploadVersionConnectResultLogDtos);
            }
            //开始导入数据源---异步导入
            ExecutorService es1 = Executors.newSingleThreadExecutor();
            es1.execute(
                    () -> {
                        importConnectSteps(versionZipDto, uploadVersionLog.getProcId(), uploadVersionLog.getId(), uploadVersionLog.getImportChangeRole());
                    }
            );
            uploadVersionLog.setImportConnect(1);
            if (Objects.equals(ImportStatusEnum.NEED_IMPORT.getId(), uploadVersionLog.getImportStatus())) {
                uploadVersionLog.setImportStatus(ImportStatusEnum.IMPORT_ING.getId());
            }
            uploadVersionLogMapper.updateById(uploadVersionLog);
        }
    }

    @Override
    public void reImportConnect(Long connectLogId) {
        UploadVersionConnectResultLog uploadVersionConnectResultLog = uploadVersionConnectResultLogMapper.selectById(connectLogId);
        if (null == uploadVersionConnectResultLog) {
            throw new RRException("不能重试！");
        }
        if (!Objects.equals(uploadVersionConnectResultLog.getImportStatus(), ImportStatusEnum.FAIL.getId())) {
            throw new RRException("不是失败状态，不能重试！");
        }
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectById(uploadVersionConnectResultLog.getUploadVersionLogId());
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), uploadVersionLog.getZipPathName(), uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        List<ConfConnectAndConfigDto> connectList = versionZipDto.getConnectList();
        if (CollectionUtil.isNotEmpty(connectList)) {
            ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(o.getId(), uploadVersionConnectResultLog.getOlderConnectDataId().intValue())).findAny().orElse(null);
            if (null != confConnectAndConfigDto) {
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                String zipEnv = versionZipDto.getZipEnv();
                String activeProfile = SpringContextUtil.getActiveProfile();
                Integer connectId = null;
                uploadVersionConnectResultLogMapper.updateStatusAndMsgById(uploadVersionConnectResultLog.getId(), ImportStatusEnum.IMPORT_ING.getId(), "");
                try {
                    connectId = importConnectInfo(confConnectAndConfigDto, zipEnv, activeProfile, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), connectLogId);
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put("【" + confConnectAndConfigDto.getName() + "】数据源", "创建失败！error:" + e.getMessage());
                    log.error("版本导入数据源异常！error:{}", e.getMessage());
                    e.printStackTrace();
                }
                //改变对应的状态
                uploadVersionConnectResultLogMapper.updateStatusAndIdByName(uploadVersionLog.getId(),
                        confConnectAndConfigDto.getId(),
                        confConnectAndConfigDto.getName(),
                        importStatus,
                        connectId,
                        JSON.toJSONString(restMsgList));
                if (1 == importStatus) {
                    throw new RRException("重试导入数据源连接失败！");
                }
            }
        }
    }

    @Override
    public UploadVersionTableResultLogSumDto tableRests(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isEmpty(versionZipDto.getTableList()) && CollectionUtil.isEmpty(versionZipDto.getRealTableList())) {
            uploadVersionLog.setImportTable(1);
            uploadVersionLogMapper.updateById(uploadVersionLog);
            UploadVersionTableResultLogSumDto uploadVersionTableResultLogSumDto = new UploadVersionTableResultLogSumDto();
            uploadVersionTableResultLogSumDto.setSumCount(0);
            uploadVersionTableResultLogSumDto.setSuccessCount(0);
            uploadVersionTableResultLogSumDto.setFailCount(0);
            uploadVersionTableResultLogSumDto.setImportStatus(ImportStatusEnum.SUCCESS.getId());
            return uploadVersionTableResultLogSumDto;
        }
        List<UploadVersionTableResultLogDto> allCheckResults = new ArrayList<>();
        List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
        if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)) {
            allCheckResults.addAll(PojoUtils.listConvert(UploadVersionTableResultLogDto.class, uploadVersionTableResultLogs));
        } else {
            List<UploadVersionTableResultLogDto> uploadVersionTableResultLogDtos = analyTable2Exit(versionZipDto.getTableList(), versionZipDto.getRealTableList(), uploadVersionLog.getId());
            if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogDtos)) {
                allCheckResults.addAll(uploadVersionTableResultLogDtos);
            }
        }
        if (CollectionUtil.isNotEmpty(allCheckResults)) {
            Long failCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
            Long successCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.SUCCESS.getId())).count();
            Integer importStatusSum = ImportStatusEnum.SUCCESS.getId();
            if (!Objects.equals(uploadVersionLog.getImportTable(), 1)) {
                importStatusSum = ImportStatusEnum.NEED_IMPORT.getId();
            }
            UploadVersionTableResultLogSumDto uploadVersionTableResultLogSumDto = new UploadVersionTableResultLogSumDto();
            uploadVersionTableResultLogSumDto.setSumCount(allCheckResults.size());
            uploadVersionTableResultLogSumDto.setSuccessCount(successCount.intValue());
            uploadVersionTableResultLogSumDto.setFailCount(failCount.intValue());
            uploadVersionTableResultLogSumDto.setImportStatus(importStatusSum);
            uploadVersionTableResultLogSumDto.setAllCheckResults(allCheckResults);
            return uploadVersionTableResultLogSumDto;
        }
        return null;
    }

    private List<UploadVersionTableResultLogDto> analyTable2Exit(List<TableInfoAndFieldDto> tableList, List<RealTableInfoAndFieldDto> realTableList, Long uploadVersionLogId) {
        List<UploadVersionTableResultLogDto> list = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(tableList)) {
            for (TableInfoAndFieldDto tableInfoAndFieldDto : tableList) {
                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", tableInfoAndFieldDto.getDbName()).eq("table_name", tableInfoAndFieldDto.getTableName()));
                Integer isExits = 0;
                UploadVersionTableResultLogDto uploadVersionTableResultLogDto = new UploadVersionTableResultLogDto();
                uploadVersionTableResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionTableResultLogDto.setDbTableName(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName());
                uploadVersionTableResultLogDto.setOlderTableDataId(Long.valueOf(tableInfoAndFieldDto.getId()));
                if (null != tableInfo) {
                    isExits = 1;
                    uploadVersionTableResultLogDto.setExitTableId(Long.valueOf(tableInfo.getId()));
                }
                uploadVersionTableResultLogDto.setIsExit(isExits);
                uploadVersionTableResultLogDto.setCreatePerName(tableInfoAndFieldDto.getCreatePerName());
                uploadVersionTableResultLogDto.setTableType(1);
                uploadVersionTableResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                list.add(uploadVersionTableResultLogDto);
            }
        }
        if (CollectionUtil.isNotEmpty(realTableList)) {
            for (RealTableInfoAndFieldDto tableInfoAndFieldDto : realTableList) {
                BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectOne(new QueryWrapper<BdpRealTableInfo>().eq("db_name", tableInfoAndFieldDto.getDbName()).eq("table_name", tableInfoAndFieldDto.getTableName()));
                Integer isExits = 0;
                UploadVersionTableResultLogDto uploadVersionTableResultLogDto = new UploadVersionTableResultLogDto();
                uploadVersionTableResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionTableResultLogDto.setDbTableName(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName());
                uploadVersionTableResultLogDto.setOlderTableDataId(Long.valueOf(tableInfoAndFieldDto.getId()));
                if (null != tableInfo) {
                    isExits = 1;
                    uploadVersionTableResultLogDto.setExitTableId(Long.valueOf(tableInfo.getId()));
                }
                uploadVersionTableResultLogDto.setIsExit(isExits);
                uploadVersionTableResultLogDto.setCreatePerName(tableInfoAndFieldDto.getCreatePerName());
                uploadVersionTableResultLogDto.setTableType(2);
                uploadVersionTableResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                list.add(uploadVersionTableResultLogDto);
            }
        }
        return list;
    }

    @Override
    public void confirmImportTables(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        if (Objects.equals(uploadVersionLog.getImportTable(), 1)) {
            throw new RRException("已经确认导入过，则不能重复导入！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isNotEmpty(versionZipDto.getTableList()) || CollectionUtil.isNotEmpty(versionZipDto.getRealTableList())) {
            List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
            if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)) {
                throw new RRException("已经确认导入过，则不能重复导入！");
            }
            //先备份，在导入
            backUps(uploadVersionLog);
            //先保存
            List<UploadVersionTableResultLogDto> uploadVersionTableResultLogDtos = analyTable2Exit(versionZipDto.getTableList(), versionZipDto.getRealTableList(), uploadVersionLog.getId());
            if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogDtos)) {
                uploadVersionTableResultLogMapper.insertBatch(uploadVersionTableResultLogDtos);
            }
            //开始导入数据源---异步导入
            ExecutorService es1 = Executors.newSingleThreadExecutor();
            es1.execute(
                    () -> {
                        importTablesSteps(versionZipDto, uploadVersionLog.getProcId(), uploadVersionLog.getId(), uploadVersionLog.getImportChangeRole());
                    }
            );
            uploadVersionLog.setImportTable(1);
            if (Objects.equals(ImportStatusEnum.NEED_IMPORT.getId(), uploadVersionLog.getImportStatus())) {
                uploadVersionLog.setImportStatus(ImportStatusEnum.IMPORT_ING.getId());
            }
            uploadVersionLogMapper.updateById(uploadVersionLog);
        }
    }

    @Override
    public void reImportTable(Long tableLogId) {
        UploadVersionTableResultLog uploadVersionTableResultLog = uploadVersionTableResultLogMapper.selectById(tableLogId);
        if (null == uploadVersionTableResultLog) {
            throw new RRException("不能重试！");
        }
        if (!Objects.equals(uploadVersionTableResultLog.getImportStatus(), ImportStatusEnum.FAIL.getId())) {
            throw new RRException("不是失败状态，不能重试！");
        }
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectById(uploadVersionTableResultLog.getUploadVersionLogId());
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), uploadVersionLog.getZipPathName(), uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        List<TableInfoAndFieldDto> tableList = versionZipDto.getTableList();
        if (CollectionUtil.isNotEmpty(tableList)) {
            TableInfoAndFieldDto tableInfoAndFieldDto = tableList.stream().filter(o -> Objects.equals(o.getId(), uploadVersionTableResultLog.getOlderTableDataId().intValue())).findAny().orElse(null);
            if (null != tableInfoAndFieldDto) {
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                String zipEnv = versionZipDto.getZipEnv();
                String activeProfile = SpringContextUtil.getActiveProfile();
                Integer tableId = null;
                uploadVersionTableResultLogMapper.updateStatusAndMsgById(uploadVersionTableResultLog.getId(), ImportStatusEnum.IMPORT_ING.getId(), "");
                try {
                    tableId = importTableInfo(tableInfoAndFieldDto, zipEnv, activeProfile, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), tableLogId);
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put("【" + tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName() + "】数据仓库", "创建失败！error:" + e.getMessage());
                    e.printStackTrace();
                }
                //改变对应的状态
                uploadVersionTableResultLogMapper.updateStatusAndIdByName(uploadVersionLog.getId(), tableInfoAndFieldDto.getId(),
                        tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(),
                        importStatus,
                        1,
                        tableId,
                        JSON.toJSONString(restMsgList));
                if (1 == importStatus) {
                    throw new RRException("重试导入数据仓库失败！");
                }
            }
        }
        List<RealTableInfoAndFieldDto> realTableList = versionZipDto.getRealTableList();
        if (CollectionUtil.isNotEmpty(realTableList)) {
            RealTableInfoAndFieldDto tableInfoAndFieldDto = realTableList.stream().filter(o -> Objects.equals(o.getId(), uploadVersionTableResultLog.getOlderTableDataId().intValue())).findAny().orElse(null);
            if (null != tableInfoAndFieldDto) {
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                String zipEnv = versionZipDto.getZipEnv();
                String activeProfile = SpringContextUtil.getActiveProfile();
                Integer tableId = null;
                uploadVersionTableResultLogMapper.updateStatusAndMsgById(uploadVersionTableResultLog.getId(), ImportStatusEnum.IMPORT_ING.getId(), "");
                try {
                    tableId = importRealTableInfo(tableInfoAndFieldDto, zipEnv, activeProfile, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), tableLogId);
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put("【" + tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName() + "】实时表", "创建失败！error:" + e.getMessage());
                    e.printStackTrace();
                }
                //改变对应的状态
                uploadVersionTableResultLogMapper.updateStatusAndIdByName(uploadVersionLog.getId(), tableInfoAndFieldDto.getId(),
                        tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(),
                        importStatus,
                        2,
                        tableId,
                        JSON.toJSONString(restMsgList));
                if (1 == importStatus) {
                    throw new RRException("重试导入实时表失败！");
                }
            }
        }
    }

    public void importTablesSteps(VersionZipDto versionZipDto, Integer procId, Long uploadVersionLogId, Integer importChangeRole) {
        //关联的数据仓库 ：库和表  同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变）
        String zipEnv = versionZipDto.getZipEnv();
        String activeProfile = SpringContextUtil.getActiveProfile();
        List<TableInfoAndFieldDto> allTableList = versionZipDto.getTableList();
        //关联的数据仓库 ：库和表  同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变包括字段表的id也不能变化）
        if (CollectionUtil.isNotEmpty(allTableList)) {
            for (TableInfoAndFieldDto tableInfoAndFieldDto : allTableList) {
                UploadVersionTableResultLog uploadVersionTableResultLog = uploadVersionTableResultLogMapper.selectOne(new QueryWrapper<UploadVersionTableResultLog>()
                        .eq("upload_version_log_id", uploadVersionLogId)
                        .eq("older_table_data_id", tableInfoAndFieldDto.getId())
                        .eq("db_table_name", tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName()));
                uploadVersionTableResultLogMapper.updateStatusByName(uploadVersionLogId, tableInfoAndFieldDto.getId(), tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(), 3, 1, "");
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                Integer tableId = null;
                try {
                    //导入表数据
                    tableId = importTableInfo(tableInfoAndFieldDto, zipEnv, activeProfile, procId, importChangeRole, uploadVersionTableResultLog == null ? null : uploadVersionTableResultLog.getId());
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(), "创建失败error:" + e.getMessage());
                    e.printStackTrace();
                }
                uploadVersionTableResultLogMapper.updateStatusAndIdByName(uploadVersionLogId, tableInfoAndFieldDto.getId(),
                        tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(),
                        importStatus,
                        1,
                        tableId,
                        JSON.toJSONString(restMsgList));
            }
        }
        List<RealTableInfoAndFieldDto> allRealTableList = versionZipDto.getRealTableList();
        //关联的实时表 ：库和表  同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变包括字段表的id也不能变化）
        if (CollectionUtil.isNotEmpty(allRealTableList)) {
            for (RealTableInfoAndFieldDto tableInfoAndFieldDto : allRealTableList) {
                UploadVersionTableResultLog uploadVersionTableResultLog = uploadVersionTableResultLogMapper.selectOne(new QueryWrapper<UploadVersionTableResultLog>()
                        .eq("upload_version_log_id", uploadVersionLogId)
                        .eq("older_table_data_id", tableInfoAndFieldDto.getId())
                        .eq("db_table_name", tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName()));
                uploadVersionTableResultLogMapper.updateStatusByName(uploadVersionLogId, tableInfoAndFieldDto.getId(), tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(), 3, 2, "");
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                Integer tableId = null;
                try {
                    //导入表数据
                    tableId = importRealTableInfo(tableInfoAndFieldDto, zipEnv, activeProfile, procId, importChangeRole, uploadVersionTableResultLog == null ? null : uploadVersionTableResultLog.getId());
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(), "创建失败error:" + e.getMessage());
                    e.printStackTrace();
                }
                uploadVersionTableResultLogMapper.updateStatusAndIdByName(uploadVersionLogId, tableInfoAndFieldDto.getId(),
                        tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName(),
                        importStatus,
                        2,
                        tableId,
                        JSON.toJSONString(restMsgList));
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public Integer importTableInfo(TableInfoAndFieldDto tableInfoAndFieldDto, String zipEnv, String activeProfile, Integer procId, Integer importChangeRole, Long tableLogId) {
        Integer tableId = null;
        Integer userId = sysUserService.getUserId(tableInfoAndFieldDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
        Integer tenantId = ShiroUtils.getTenantId();
        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", tableInfoAndFieldDto.getDbName()).eq("table_name", tableInfoAndFieldDto.getTableName()));
        //Integer isExit = 0;
        if (null == tableInfo) {
            log.error("数据仓库：【{}.{}】不存在", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
            //直接新建,并且关联到这个项目
            tableId = insertOrUpdateTable(tableInfoAndFieldDto, procId, null, null, 0L, 0D, tableInfoAndFieldDto.getUpdateTime(), importChangeRole, tenantId, null);
            //初始化权限
            if (null == importChangeRole) {
                tableInfoService.initDataPermission(tableId, null, userId);
            }
        } else {
            //isExit = 1;
            tableId = tableInfo.getId();
            //先删除，再新建id保持不变
            List<TableFieldInfo> olderTbaleFields = tableFieldInfoMapper.selectList(new QueryWrapper<TableFieldInfo>().eq("table_id", tableInfo.getId()));
            Date nowDates = tableInfo.getUpdateTime() == null ? new Date() : tableInfo.getUpdateTime();
            if (!StorageEngineEnum.KUDU.getCode().equals(tableInfo.getStoreEngine())) {
                olderTbaleFields = deleteTables(procId, tableInfo, false, importChangeRole);
            }
            insertOrUpdateTable(tableInfoAndFieldDto, procId, tableInfo.getId(), olderTbaleFields, tableInfo.getRowsNum(), tableInfo.getTotalSize(), nowDates, importChangeRole, tableInfo.getTenantId(), tableInfo);
            //没有就关联一下
            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 1));
            if (null == procTable) {
                procTable = new ProcTable();
                procTable.setTableId(tableInfo.getId());
                procTable.setProcId(procId);
                procTableMapper.insert(procTable);
            }
            //如果导入的表不在本租户，跨租户授权
            Integer oldTenantId = tableInfo.getTenantId();
            if (oldTenantId != null && tenantId != null && Objects.equals(oldTenantId,tenantId)) {
                List<SysTenantDataPermission> permissionList = new ArrayList<>();
                SysTenantDataPermission tablePermission=new SysTenantDataPermission();
                tablePermission.setTenantId(tenantId);
                tablePermission.setDataId(tableId);
                tablePermission.setDataType(2);
                tablePermission.setQuery(1);
                tablePermission.setAssign(1);
                tablePermission.setCreate(1);
                tablePermission.setDecrypt(1);
                tablePermission.setDelete(1);
                tablePermission.setExport(1);
                tablePermission.setUpdate(1);
                tablePermission.setWrite(1);
                permissionList.add(tablePermission);
                if(CollectionUtil.isNotEmpty(olderTbaleFields)){
                    for(TableFieldInfo field:olderTbaleFields){
                        SysTenantDataPermission fieldPermission=new SysTenantDataPermission();
                        fieldPermission.setTenantId(tenantId);
                        fieldPermission.setDataId(field.getId());
                        fieldPermission.setDataType(3);
                        fieldPermission.setQuery(1);
                        fieldPermission.setAssign(1);
                        fieldPermission.setCreate(1);
                        fieldPermission.setDecrypt(1);
                        fieldPermission.setDelete(1);
                        fieldPermission.setExport(1);
                        fieldPermission.setUpdate(1);
                        fieldPermission.setWrite(1);
                        permissionList.add(fieldPermission);
                    }
                }
                dataPermissionService.saveTenantPermission(permissionList);
            }

//            //不管是什么环境都要先删除后创建
//            if(!Objects.equals(zipEnv, activeProfile)){
//
//            }else{
//
//            }
        }
        //uploadVersionTableResultLogMapper.updateIsExitById(tableLogId,isExit);
        //创建表和字段权限
        if (null != importChangeRole) {
            tableInfoService.initDataPermission(tableId, Long.valueOf(importChangeRole), userId);
        }
        return tableId;
    }

    @Transactional(rollbackFor = Exception.class)
    public Integer importRealTableInfo(RealTableInfoAndFieldDto tableInfoAndFieldDto, String zipEnv, String activeProfile, Integer procId, Integer importChangeRole, Long tableLogId) {
        Integer tableId = null;
        Integer userId = sysUserService.getUserId(tableInfoAndFieldDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
        Integer tenantId = ShiroUtils.getTenantId();
        BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectOne(new QueryWrapper<BdpRealTableInfo>().eq("db_name", tableInfoAndFieldDto.getDbName()).eq("table_name", tableInfoAndFieldDto.getTableName()));
        //Integer isExit = 0;
        if (null == tableInfo) {
            log.error("实时表：【{}.{}】不存在", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
            //直接新建,并且关联到这个项目
            tableId = insertOrUpdateRealTable(tableInfoAndFieldDto, procId, null, null, tableInfoAndFieldDto.getUpdateTime(), importChangeRole, tenantId, null);
            //初始化权限
            if (null == importChangeRole) {
                realTableInfoService.initDataPermission(tableId, null, userId);
            }
        } else {
            //isExit = 1;
            tableId = tableInfo.getId();
            //先删除，再新建id保持不变
            List<BdpRealTableField> olderTbaleFields = realTableFieldMapper.selectList(new QueryWrapper<BdpRealTableField>().eq("table_id", tableInfo.getId()));
            Date nowDates = tableInfo.getUpdateTime() == null ? new Date() : tableInfo.getUpdateTime();
            insertOrUpdateRealTable(tableInfoAndFieldDto, procId, tableInfo.getId(), olderTbaleFields, nowDates, importChangeRole, tableInfo.getTenantId(), tableInfo);
            //没有就关联一下
            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 2));
            if (null == procTable) {
                procTable = new ProcTable();
                procTable.setTableId(tableInfo.getId());
                procTable.setProcId(procId);
                procTable.setTableType(2);
                procTableMapper.insert(procTable);
            }
            //如果导入的表不在本租户，跨租户授权
            Integer oldTenantId = tableInfo.getTenantId();
            if (oldTenantId != null && tenantId != null && Objects.equals(oldTenantId,tenantId)) {
                List<SysTenantDataPermission> permissionList = new ArrayList<>();
                SysTenantDataPermission tablePermission=new SysTenantDataPermission();
                tablePermission.setTenantId(tenantId);
                tablePermission.setDataId(tableId);
                tablePermission.setDataType(6);
                tablePermission.setQuery(1);
                tablePermission.setAssign(1);
                tablePermission.setCreate(1);
                tablePermission.setDecrypt(1);
                tablePermission.setDelete(1);
                tablePermission.setExport(1);
                tablePermission.setUpdate(1);
                tablePermission.setWrite(1);
                permissionList.add(tablePermission);
                if(CollectionUtil.isNotEmpty(olderTbaleFields)){
                    for(BdpRealTableField field:olderTbaleFields){
                        SysTenantDataPermission fieldPermission=new SysTenantDataPermission();
                        fieldPermission.setTenantId(tenantId);
                        fieldPermission.setDataId(field.getId());
                        fieldPermission.setDataType(7);
                        fieldPermission.setQuery(1);
                        fieldPermission.setAssign(1);
                        fieldPermission.setCreate(1);
                        fieldPermission.setDecrypt(1);
                        fieldPermission.setDelete(1);
                        fieldPermission.setExport(1);
                        fieldPermission.setUpdate(1);
                        fieldPermission.setWrite(1);
                        permissionList.add(fieldPermission);
                    }
                }
                dataPermissionService.saveTenantPermission(permissionList);
            }
        }
        //创建表和字段权限
        if (null != importChangeRole) {
            realTableInfoService.initDataPermission(tableId, Long.valueOf(importChangeRole), userId);
        }
        return tableId;
    }

    @Override
    public UploadVersionWorkFlowResultLogSumDto workflowRests(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isEmpty(versionZipDto.getWorkMenuList()) && CollectionUtil.isEmpty(versionZipDto.getRealWorkMenuList())) {
            uploadVersionLog.setImportWorkflow(1);
            uploadVersionLogMapper.updateById(uploadVersionLog);
            UploadVersionWorkFlowResultLogSumDto uploadVersionWorkFlowResultLogSumDto = new UploadVersionWorkFlowResultLogSumDto();
            uploadVersionWorkFlowResultLogSumDto.setSumCount(0);
            uploadVersionWorkFlowResultLogSumDto.setSuccessCount(0);
            uploadVersionWorkFlowResultLogSumDto.setFailCount(0);
            uploadVersionWorkFlowResultLogSumDto.setImportStatus(ImportStatusEnum.SUCCESS.getId());
            return uploadVersionWorkFlowResultLogSumDto;
        }
        List<UploadVersionWorkflowResultLogDto> allCheckResults = new ArrayList<>();
        List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper
                .selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                        .eq("upload_version_log_id", uploadVersionLog.getId())
                        .in("import_type", 0, 1, 3));
        if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
            allCheckResults.addAll(PojoUtils.listConvert(UploadVersionWorkflowResultLogDto.class, uploadVersionWorkflowResultLogs));
        } else {
            List<UploadVersionWorkflowResultLogDto> uploadVersionWorkflowResultLogDtos = analyWorkflow2Exit(versionZipDto.getWorkMenuList(), versionZipDto.getRealWorkMenuList(), uploadVersionLog.getId(), uploadVersionLog.getProcId(), Boolean.FALSE);
            if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogDtos)) {
                allCheckResults.addAll(uploadVersionWorkflowResultLogDtos);
            }
        }
        if (CollectionUtil.isNotEmpty(allCheckResults)) {
            Long failCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.FAIL.getId())).count();
            Long successCount = allCheckResults.stream().filter(o -> Objects.equals(o.getImportStatus(), ImportStatusEnum.SUCCESS.getId())).count();
            Integer importStatusSum = ImportStatusEnum.SUCCESS.getId();
            if (!Objects.equals(uploadVersionLog.getImportWorkflow(), 1)) {
                importStatusSum = ImportStatusEnum.NEED_IMPORT.getId();
            }
            UploadVersionWorkFlowResultLogSumDto uploadVersionWorkFlowResultLogSumDto = new UploadVersionWorkFlowResultLogSumDto();
            uploadVersionWorkFlowResultLogSumDto.setSumCount(allCheckResults.size());
            uploadVersionWorkFlowResultLogSumDto.setSuccessCount(successCount.intValue());
            uploadVersionWorkFlowResultLogSumDto.setFailCount(failCount.intValue());
            uploadVersionWorkFlowResultLogSumDto.setImportStatus(importStatusSum);
            uploadVersionWorkFlowResultLogSumDto.setAllCheckResults(allCheckResults);
            return uploadVersionWorkFlowResultLogSumDto;
        }
        return null;
    }

    private List<UploadVersionWorkflowResultLogDto> analyWorkflow2Exit(List<WorkMenuAndLayDto> workMenuList, List<RealTimeTaskMenuAndTaskDto> realWorkMenuList, Long uploadVersionLogId, Integer procId, Boolean isContianOthers) {
        List<UploadVersionWorkflowResultLogDto> list = new ArrayList<>();
        //查询到当前工程下对应的菜单
        List<WorkMenu> newWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
        packNewTmpPathName(newWorkMenus);//新的所有路径的名称
        //挑选出来所有的工作流
        List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
        filterAllWorkFlowNameAndLayName(workMenuList, allWorkFlowNames, Boolean.FALSE, Boolean.TRUE, newWorkMenus, Boolean.TRUE);
        if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
            for (VersionWorkflowDto allWorkFlowName : allWorkFlowNames) {
                UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = new UploadVersionWorkflowResultLogDto();
                uploadVersionWorkflowResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionWorkflowResultLogDto.setWorkflowMenuName(allWorkFlowName.getName());
                uploadVersionWorkflowResultLogDto.setOlderRootId(allWorkFlowName.getOlderRootId());
                uploadVersionWorkflowResultLogDto.setOlderWorkflowDataId(allWorkFlowName.getOlderId());
                uploadVersionWorkflowResultLogDto.setImportType(0);
                uploadVersionWorkflowResultLogDto.setIsExit(allWorkFlowName.getIsExit());
                uploadVersionWorkflowResultLogDto.setExitRootId(allWorkFlowName.getExitRootId());
                uploadVersionWorkflowResultLogDto.setExitWorkflowId(allWorkFlowName.getExitWorkflowId());
                uploadVersionWorkflowResultLogDto.setCreatePerName(allWorkFlowName.getCreateName());
                uploadVersionWorkflowResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                uploadVersionWorkflowResultLogDto.setFlowType(1);
                list.add(uploadVersionWorkflowResultLogDto);
            }
        }
        //挑选出来所有的工作流
        List<VersionWorkflowDto> allWorkFlowLayNames = new ArrayList<>();
        filterAllWorkFlowNameAndLayName(workMenuList, allWorkFlowLayNames, Boolean.TRUE, Boolean.FALSE, newWorkMenus, Boolean.TRUE);
        if (CollectionUtil.isNotEmpty(allWorkFlowLayNames)) {
            for (VersionWorkflowDto allWorkFlowName : allWorkFlowLayNames) {
                UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = new UploadVersionWorkflowResultLogDto();
                uploadVersionWorkflowResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionWorkflowResultLogDto.setWorkflowMenuName(allWorkFlowName.getName());
                uploadVersionWorkflowResultLogDto.setOlderRootId(allWorkFlowName.getOlderRootId());
                uploadVersionWorkflowResultLogDto.setOlderWorkflowDataId(allWorkFlowName.getOlderId());
                uploadVersionWorkflowResultLogDto.setImportType(1);
                uploadVersionWorkflowResultLogDto.setIsExit(allWorkFlowName.getIsExit());
                uploadVersionWorkflowResultLogDto.setExitRootId(allWorkFlowName.getExitRootId());
                uploadVersionWorkflowResultLogDto.setExitWorkflowId(allWorkFlowName.getExitWorkflowId());
                uploadVersionWorkflowResultLogDto.setCreatePerName(allWorkFlowName.getCreateName());
                uploadVersionWorkflowResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                uploadVersionWorkflowResultLogDto.setFlowType(1);
                list.add(uploadVersionWorkflowResultLogDto);
            }
        }
        //查询到当前工程下对应的实时任务菜单
        List<RealTimeTaskMenu> newRealWorkMenus = realTimeTaskMenuMapper.selectList(new QueryWrapper<RealTimeTaskMenu>().eq("proc_id", procId).eq("state", 1));
        packNewRealTmpPathName(newRealWorkMenus);
        //挑选出来所有的实时任务
        List<VersionWorkflowDto> allRealWorkFlowNames = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
            filterAllRealWorkFlowName(realWorkMenuList, allRealWorkFlowNames, newRealWorkMenus, Boolean.TRUE);
            if (CollectionUtil.isNotEmpty(allRealWorkFlowNames)) {
                for (VersionWorkflowDto allWorkFlowName : allRealWorkFlowNames) {
                    UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = new UploadVersionWorkflowResultLogDto();
                    uploadVersionWorkflowResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                    uploadVersionWorkflowResultLogDto.setWorkflowMenuName(allWorkFlowName.getName());
                    uploadVersionWorkflowResultLogDto.setOlderRootId(allWorkFlowName.getOlderRootId());
                    uploadVersionWorkflowResultLogDto.setOlderWorkflowDataId(allWorkFlowName.getOlderId());
                    uploadVersionWorkflowResultLogDto.setImportType(3);
                    uploadVersionWorkflowResultLogDto.setIsExit(allWorkFlowName.getIsExit());
                    uploadVersionWorkflowResultLogDto.setExitRootId(allWorkFlowName.getExitRootId());
                    uploadVersionWorkflowResultLogDto.setExitWorkflowId(allWorkFlowName.getExitWorkflowId());
                    uploadVersionWorkflowResultLogDto.setCreatePerName(allWorkFlowName.getCreateName());
                    uploadVersionWorkflowResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                    uploadVersionWorkflowResultLogDto.setFlowType(2);
                    list.add(uploadVersionWorkflowResultLogDto);
                }
            }
        }
        if (isContianOthers) {
            //按照根菜单进行名字查找看是否存在。当前工程下
            List<List<WorkMenuAndLayDto>> packWorkMenuAndLayDtoLists = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(workMenuList)) {
                //一层一层来生成
                Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = workMenuList.stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
                for (Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()) {
                    List<WorkMenuAndLayDto> tempList = genPackWorkMenus(entry, newWorkMenus);
                    if (CollectionUtil.isNotEmpty(tempList)) {
                        packWorkMenuAndLayDtoLists.add(tempList);
                    }
                }
            }
            for (List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList : packWorkMenuAndLayDtoLists) {
                if (CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoList)) {
                    List<WorkMenuAndLayDto> others = packWorkMenuAndLayDtoList.stream().filter(o -> (!Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode()) && !Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode()))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(others)) {
                        for (WorkMenuAndLayDto other : others) {
                            UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = new UploadVersionWorkflowResultLogDto();
                            uploadVersionWorkflowResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                            uploadVersionWorkflowResultLogDto.setWorkflowMenuName(other.getName());
                            uploadVersionWorkflowResultLogDto.setOlderRootId(other.getRootId());
                            uploadVersionWorkflowResultLogDto.setOlderWorkflowDataId(other.getId());
                            uploadVersionWorkflowResultLogDto.setImportType(2);
                            Integer isExit = null == other.getNewId() ? 0 : 1;
                            Long exitRootId = null == other.getNewRootId() ? 0L : other.getNewRootId();
                            Long exitId = null == other.getNewId() ? 0L : other.getNewId();
                            uploadVersionWorkflowResultLogDto.setIsExit(isExit);
                            uploadVersionWorkflowResultLogDto.setExitRootId(exitRootId);
                            uploadVersionWorkflowResultLogDto.setExitWorkflowId(exitId);
                            uploadVersionWorkflowResultLogDto.setCreatePerName(other.getCreatePerName());
                            uploadVersionWorkflowResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                            uploadVersionWorkflowResultLogDto.setFlowType(1);
                            list.add(uploadVersionWorkflowResultLogDto);
                        }
                    }
                }

            }
            //按照根菜单进行名字查找看是否存在。当前工程下
            List<List<RealTimeTaskMenuAndTaskDto>> packRealWorkMenuAndLayDtoLists = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
                List<RealTimeTaskMenuAndTaskDto> olderRootWorkMenuLists = realWorkMenuList.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());

                for (RealTimeTaskMenuAndTaskDto entry : olderRootWorkMenuLists) {
                    List<RealTimeTaskMenuAndTaskDto> tempList = genPackRealWorkMenus(entry.getId(), realWorkMenuList, newRealWorkMenus);
                    if (CollectionUtil.isNotEmpty(tempList)) {
                        packRealWorkMenuAndLayDtoLists.add(tempList);
                    }
                }
            }
            for (List<RealTimeTaskMenuAndTaskDto> packWorkMenuAndLayDtoList : packRealWorkMenuAndLayDtoLists) {
                if (CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoList)) {
                    List<RealTimeTaskMenuAndTaskDto> root = packWorkMenuAndLayDtoList.stream().filter(o -> o.getParentId().equals(0)).collect(Collectors.toList());
                    Integer rootId = null;
                    if (CollectionUtil.isNotEmpty(root)) {
                        rootId = root.get(0).getId();
                    }
                    List<RealTimeTaskMenuAndTaskDto> others = packWorkMenuAndLayDtoList.stream().filter(o -> (!Objects.equals(o.getMenuType(), 2))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(others)) {
                        for (RealTimeTaskMenuAndTaskDto other : others) {
                            UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = new UploadVersionWorkflowResultLogDto();
                            uploadVersionWorkflowResultLogDto.setUploadVersionLogId(uploadVersionLogId);
                            uploadVersionWorkflowResultLogDto.setWorkflowMenuName(other.getName());
                            uploadVersionWorkflowResultLogDto.setOlderWorkflowDataId(Long.valueOf(other.getId()));
                            uploadVersionWorkflowResultLogDto.setOlderRootId(Long.valueOf(rootId));
                            uploadVersionWorkflowResultLogDto.setImportType(4);
                            Integer isExit = null == other.getNewId() ? 0 : 1;
                            Long exitId = null == other.getNewId() ? 0L : other.getNewId();
                            uploadVersionWorkflowResultLogDto.setIsExit(isExit);
                            uploadVersionWorkflowResultLogDto.setExitWorkflowId(exitId);
                            uploadVersionWorkflowResultLogDto.setCreatePerName(other.getCreatePerName());
                            uploadVersionWorkflowResultLogDto.setImportStatus(ImportStatusEnum.NEED_IMPORT.getId());
                            uploadVersionWorkflowResultLogDto.setFlowType(2);
                            list.add(uploadVersionWorkflowResultLogDto);
                        }
                    }
                }

            }
        }
        return list;
    }

    @Override
    public void confirmImportWorkflows(String zipPathName) {
        //检测上传的版本包中的项目
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", zipPathName));
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        if (uploadVersionLog.getImportStep() != null
                && uploadVersionLog.getImportStep() >= ImportStepEnum.IMPORT_WORKFLOW_ING.getId()) {
            throw new RRException("已经确认导入过，则不能重复导入！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), zipPathName, uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        if (CollectionUtil.isNotEmpty(versionZipDto.getWorkMenuList()) || CollectionUtil.isNotEmpty(versionZipDto.getRealWorkMenuList())) {
            List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>().eq("upload_version_log_id", uploadVersionLog.getId()));
            if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                throw new RRException("已经确认导入过，则不能重复导入！");
            }
            //先备份，在导入
            backUps(uploadVersionLog);
            //先初始化保存数据
            List<UploadVersionWorkflowResultLogDto> uploadVersionWorkflowResultLogDtos = analyWorkflow2Exit(versionZipDto.getWorkMenuList(), versionZipDto.getRealWorkMenuList(), uploadVersionLog.getId(), uploadVersionLog.getProcId(), Boolean.TRUE);
            if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogDtos)) {
                uploadVersionWorkflowResultLogMapper.insertBatch(uploadVersionWorkflowResultLogDtos);
            }
            //开始导入工作流---异步导入
            ExecutorService es1 = Executors.newSingleThreadExecutor();
            es1.execute(
                    () -> {
                        importWorkflowsSteps(versionZipDto, uploadVersionLog.getProcId(), uploadVersionLog.getId(), uploadVersionLog.getImportChangeRole(), uploadVersionWorkflowResultLogDtos);
                    }
            );
            uploadVersionLog.setImportWorkflow(1);
            if (Objects.equals(ImportStatusEnum.NEED_IMPORT.getId(), uploadVersionLog.getImportStatus())) {
                uploadVersionLog.setImportStatus(ImportStatusEnum.IMPORT_ING.getId());
            }
            uploadVersionLogMapper.updateById(uploadVersionLog);
        }
    }

    @Override
    public void reImportWorkflows(Long workflowLogId) {
        Integer tenantId = ShiroUtils.getTenantId();
        UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog = uploadVersionWorkflowResultLogMapper.selectById(workflowLogId);
        if (null == uploadVersionWorkflowResultLog) {
            throw new RRException("不能重试！");
        }
        if (!Objects.equals(uploadVersionWorkflowResultLog.getImportStatus(), ImportStatusEnum.FAIL.getId())) {
            throw new RRException("不是失败状态，不能重试！");
        }
//        //其父菜单都错了,则不能重试（暂时处理成这样）。待重新生成对应的父级菜单
//        if(Objects.equals(uploadVersionWorkflowResultLog.getParentMenuFlage(),1)){
//            throw new RRException(uploadVersionWorkflowResultLog.getRestMsgList());
//        }
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectById(uploadVersionWorkflowResultLog.getUploadVersionLogId());
        if (null == uploadVersionLog) {
            throw new RRException("版本包资源不存在！");
        }
        //查询需要导入的连接的个数
        VersionZipDto versionZipDto = upAndAnlagZip(uploadVersionLog.getProcId(), uploadVersionLog.getZipPathName(), uploadVersionLog.getImportAllJson());
        if (null == versionZipDto) {
            throw new RRException("版本包文件格式不正确！");
        }
        List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            //找到这个根目录下所有的菜单
            List<WorkMenuAndLayDto> rootLists = workMenuList.stream().filter(o -> Objects.equals(o.getRootId(), uploadVersionWorkflowResultLog.getOlderRootId())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(rootLists)) {
                //查询到当前工程下对应的菜单
                List<WorkMenu> newWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", uploadVersionLog.getProcId()));
                packNewTmpPathName(newWorkMenus);//新的所有路径的名称
                //一层一层来生成
                Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = new HashMap<>();
                olderWorkMenuMaps.put(uploadVersionWorkflowResultLog.getOlderRootId(), rootLists);
                //按照根菜单进行名字查找看是否存在。当前工程下
                List<List<WorkMenuAndLayDto>> packWorkMenuAndLayDtoLists = new ArrayList<>();
                for (Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()) {
                    List<WorkMenuAndLayDto> tempList = genPackWorkMenus(entry, newWorkMenus);
                    if (CollectionUtil.isNotEmpty(tempList)) {
                        packWorkMenuAndLayDtoLists.add(tempList);
                    }
                }
                //这里实际上就一个根目录
                if (CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoLists)) {
                    for (List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList : packWorkMenuAndLayDtoLists) {
                        //以根目录为单位，进行创建
                        Integer errorFlage = 0;
                        List<WorkMenuAndLayDto> workFlowLays = new ArrayList<>();
                        List<WorkMenuAndLayDto> otherWorkFlows = new ArrayList<>();
                        packWorkMenuAndLayDtoList.forEach(o -> {
                            if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())) {
                                workFlowLays.add(o);
                            } else {
                                otherWorkFlows.add(o);
                            }
                        });
                        //查询到这个根目录下的所有的其它目录是否创建（如果没有，则需要重新创建）
                        List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                .eq("upload_version_log_id", uploadVersionLog.getId())
                                .eq("older_root_id", uploadVersionWorkflowResultLog.getOlderRootId())
                                .eq("import_type", 2));
                        if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                            List<UploadVersionWorkflowResultLog> collect = uploadVersionWorkflowResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), 1)).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(collect)) {
                                //其有对应的父级目录创建失败（先创建父级菜单目录）
                                //先排序，让菜单的顺序一样
                                Long newRootId = 0L;
                                List<WorkMenuAndLayDto> dataList = otherWorkFlows.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
                                for (WorkMenuAndLayDto otherWorkFlow : dataList) {
                                    //根目录
                                    if (Objects.equals(0L, otherWorkFlow.getParentId())) {
                                        if (null == otherWorkFlow.getNewId()) {
                                            try {
                                                WorkMenu one = addRootWorkMenuDto(otherWorkFlow, uploadVersionLog.getProcId());

                                                //重置新的id
                                                otherWorkFlow.setNewRootId(one.getId());
                                                otherWorkFlow.setNewProcId(Long.valueOf(uploadVersionLog.getProcId()));
                                                otherWorkFlow.setNewParentId(0L);
                                                otherWorkFlow.setNewId(one.getId());
                                                newRootId = one.getId();

                                                uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), otherWorkFlow.getId(), otherWorkFlow.getRootId(), one.getId(), 0, "");

                                            } catch (Exception e) {
                                                errorFlage = 1;
                                                //创建根目录异常
                                                log.error("生成根目录失败！error:{}", e.getMessage());
                                                //这个根目录下的所有的工作流全部失败
                                                Map<String, String> restMsgList = new HashMap<>();
                                                restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                                uploadVersionWorkflowResultLogMapper.updateStatusByRootId(uploadVersionLog.getId(), otherWorkFlow.getRootId(), 1, JSON.toJSONString(restMsgList));
                                                //直接跳出循环
                                                break;
                                            }
                                        } else {
                                            newRootId = otherWorkFlow.getNewRootId();
                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), otherWorkFlow.getId(), otherWorkFlow.getRootId(), otherWorkFlow.getNewId(), 0, "");
                                        }
                                    }
                                    //子目录 或者 作业流血缘管理文件夹
                                    if (Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.SUB_DIR.getCode())
                                            || Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT.getCode())
                                            || Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.SUB_SUB_DIR.getCode())) {
                                        if (null == otherWorkFlow.getNewId()) {
                                            try {
                                                WorkMenuAndLayDto workMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                                WorkMenu subOne = addWorkFlowMGTAndSubDto(otherWorkFlow, uploadVersionLog.getProcId(), workMenuAndLayDto.getNewId(), newRootId);

                                                //重置新的id
                                                otherWorkFlow.setNewRootId(subOne.getRootId());
                                                otherWorkFlow.setNewProcId(Long.valueOf(uploadVersionLog.getProcId()));
                                                otherWorkFlow.setNewParentId(workMenuAndLayDto.getNewId());
                                                otherWorkFlow.setNewId(subOne.getId());

                                                uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), otherWorkFlow.getId(), otherWorkFlow.getRootId(), subOne.getId(), 0, "");

                                            } catch (Exception e) {
                                                errorFlage = 1;
                                                //创建目录异常
                                                log.error("生成目录失败！error:{}", e.getMessage());
                                                //这个目录下的所有的工作流全部失败
                                                Map<String, String> restMsgList = new HashMap<>();
                                                restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                                uploadVersionWorkflowResultLogMapper.updateStatusByRootId(uploadVersionLog.getId(), otherWorkFlow.getRootId(), 1, JSON.toJSONString(restMsgList));
                                                //直接跳出循环
                                                break;
                                            }
                                        } else {
                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), otherWorkFlow.getId(), otherWorkFlow.getRootId(), otherWorkFlow.getNewId(), 0, "");
                                        }
                                    }
                                }
                            }
                        }

                        //如果生成父级菜单目录还是失败，则还是不能生成下面的工作流和工作流依赖
                        String errMsg = "";
                        Integer importType = uploadVersionWorkflowResultLog.getImportType();
                        if (Objects.equals(importType, 0)) {
                            errMsg = "重试导入工作流失败！";
                        }
                        if (Objects.equals(importType, 1)) {
                            errMsg = "重试导入工作流依赖失败！";
                        }
                        if (Objects.equals(1, errorFlage)) {
                            throw new RRException(errMsg);
                        }

                        //导入状态  0：成功  1：失败  2：待导入  3：导入中
                        Integer importStatus = 0;
                        Map<String, String> restMsgList = new HashMap<>();
                        WorkMenuAndLayDto workMenuAndLayDto = packWorkMenuAndLayDtoList.stream().filter(o -> Objects.equals(o.getId(), uploadVersionWorkflowResultLog.getOlderWorkflowDataId())).findAny().orElse(null);
                        if (null == workMenuAndLayDto) {
                            throw new RRException("未找到创建项！");
                        }

                        //导入开始
                        uploadVersionWorkflowResultLogMapper.updateStatusAndMsgById(uploadVersionWorkflowResultLog.getId(), ImportStatusEnum.IMPORT_ING.getId(), "");
                        Long newJobId = 0L;
                        //Integer isExit = 0;
                        if (Objects.equals(importType, 0)) {
                            //作业流
                            WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), workMenuAndLayDto.getParentId())).findAny().orElse(null);
                            JobInfoDto jobInfoDto = workMenuAndLayDto.getJobInfoDto();
                            if (null == workMenuAndLayDto.getNewId()) {
                                //新增作业流和其任务和对应的节点和配置信息(直接新增)
                                try {
                                    genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto, workMenuAndLayDto, uploadVersionLog.getProcId(), workMenuAndLayDto.getNewRootId(), versionZipDto, jobInfoDto, null, null, null, null, uploadVersionWorkflowResultLog.getId(), tenantId);
                                } catch (Exception e) {
                                    log.error("生成工作流:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    importStatus = 1;
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "创建失败error:" + e.getMessage());
                                }
                            } else {
                                //isExit = 1;
                                //编辑作业流（id不能变，其如果依赖作业流依赖，还得先停掉作业流依赖，然后重新生成作业流，然后重新保存对应的作业流依赖）
                                List<JobNodeInfo> olderJobNodeInfos = new ArrayList<>();
                                WorkMenu workMenuLay = new WorkMenu();
                                Integer jobId = deleteAllInfoByWorkMenuId(workMenuAndLayDto.getNewId(), olderJobNodeInfos, workMenuLay);
                                jobInfoDto.setNewId(jobId);
                                try {
                                    genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto, workMenuAndLayDto, uploadVersionLog.getProcId(), workMenuAndLayDto.getNewRootId(), versionZipDto, jobInfoDto, olderJobNodeInfos, workMenuAndLayDto.getNewId(), jobId, workMenuLay.getId(), uploadVersionWorkflowResultLog.getId(), tenantId);
                                } catch (Exception e) {
                                    log.error("生成工作流:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    importStatus = 1;
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "修改失败error:" + e.getMessage());
                                }
                            }
                            newJobId = null == jobInfoDto.getNewId() ? null : Long.valueOf(jobInfoDto.getNewId());
                        }
                        if (Objects.equals(importType, 1)) {
                            //组装工作流对应的需要的工作流信息
                            List<JobInfoDto> jobDtos = initAllCreateJobByProcId(otherWorkFlows, uploadVersionWorkflowResultLog.getOlderRootId(), uploadVersionWorkflowResultLog.getUploadVersionLogId());
                            //作业流依赖
                            WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT.getCode())).findAny().orElse(null);
                            if (null == workMenuAndLayDto.getNewId()) {
                                try {
                                    genWorkFlowLayAndConfig(parentWorkMenuAndLayDto, workMenuAndLayDto, uploadVersionLog.getProcId(), workMenuAndLayDto.getNewRootId(), jobDtos, null, null, uploadVersionWorkflowResultLog.getId());
                                    newJobId = workMenuAndLayDto.getWorkFlowDepDto().getNewId();
                                } catch (Exception e) {
                                    log.error("生成工作流依赖:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    importStatus = 1;
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "新增失败error:" + e.getMessage());
                                    //先删除后新增
                                    deleteAllInfoByWorkMenuLayId(workMenuAndLayDto.getNewId());
                                }
                            } else {
                                //isExit = 1;
                                //先删除后新增
                                Long workDepId = deleteAllInfoByWorkMenuLayId(workMenuAndLayDto.getNewId());
                                try {
                                    genWorkFlowLayAndConfig(parentWorkMenuAndLayDto, workMenuAndLayDto, uploadVersionLog.getProcId(), workMenuAndLayDto.getNewRootId(), jobDtos, workMenuAndLayDto.getNewId(), workDepId, uploadVersionWorkflowResultLog.getId());
                                } catch (Exception e) {
                                    log.error("生成工作流依赖:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    importStatus = 1;
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "修改失败error:" + e.getMessage());
                                }
                                newJobId = workDepId;
                            }
                        }
                        //uploadVersionWorkflowResultLogMapper.updateIsExitById(null == uploadVersionWorkflowResultLog ?  null : uploadVersionWorkflowResultLog.getId(),isExit);

                        //导入工作流完成
                        uploadVersionWorkflowResultLogMapper.updateStatusAndJobByName(uploadVersionLog.getId(),
                                workMenuAndLayDto.getId(),
                                uploadVersionWorkflowResultLog.getWorkflowMenuName(),
                                importStatus,
                                1,
                                newJobId,
                                JSON.toJSONString(restMsgList));
                        if (1 == importStatus) {
                            throw new RRException(errMsg);
                        }
                    }
                }
            }
        }

        List<RealTimeTaskMenuAndTaskDto> realWorkMenuList = versionZipDto.getRealWorkMenuList();
        //查询到当前工程下对应的实时任务菜单
        List<RealTimeTaskMenu> newRealWorkMenus = realTimeTaskMenuMapper.selectList(new QueryWrapper<RealTimeTaskMenu>().eq("proc_id", uploadVersionLog.getProcId()).eq("state", 1));
        if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
            List<RealTimeTaskMenuAndTaskDto> rootList = genPackRealWorkMenus(uploadVersionWorkflowResultLog.getOlderRootId().intValue(), realWorkMenuList, newRealWorkMenus);
            packNewRealTmpPathName(newRealWorkMenus);
            //找到这个根目录下所有的菜单
            if (CollectionUtil.isNotEmpty(rootList)) {
                //一层一层来生成
                Map<Long, List<RealTimeTaskMenuAndTaskDto>> olderWorkMenuMaps = new HashMap<>();
                olderWorkMenuMaps.put(uploadVersionWorkflowResultLog.getOlderRootId(), rootList);
                //按照根菜单进行名字查找看是否存在。当前工程下
                List<List<RealTimeTaskMenuAndTaskDto>> packWorkMenuAndLayDtoLists = new ArrayList<>();
                for (Map.Entry<Long, List<RealTimeTaskMenuAndTaskDto>> entry : olderWorkMenuMaps.entrySet()) {
                    List<RealTimeTaskMenuAndTaskDto> tempList = genPackRealWorkMenus(entry.getKey().intValue(), entry.getValue(), newRealWorkMenus);
                    if (CollectionUtil.isNotEmpty(tempList)) {
                        packWorkMenuAndLayDtoLists.add(tempList);
                    }
                }
                //这里实际上就一个根目录
                if (CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoLists)) {
                    for (List<RealTimeTaskMenuAndTaskDto> packWorkMenuAndLayDtoList : packWorkMenuAndLayDtoLists) {
                        //以根目录为单位，进行创建
                        Integer errorFlage = 0;
                        List<RealTimeTaskMenuAndTaskDto> workFlows = new ArrayList<>();
                        List<RealTimeTaskMenuAndTaskDto> otherWorkFlows = new ArrayList<>();
                        packWorkMenuAndLayDtoList.forEach(o -> {
                            if (o.getMenuType() == 2) {
                                workFlows.add(o);
                            } else {
                                otherWorkFlows.add(o);
                            }
                        });
                        //查询到这个根目录下的所有的其它目录是否创建（如果没有，则需要重新创建）
                        List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                .eq("upload_version_log_id", uploadVersionLog.getId())
                                .eq("older_root_id", uploadVersionWorkflowResultLog.getOlderRootId())
                                .eq("import_type", 4));
                        if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                            List<UploadVersionWorkflowResultLog> collect = uploadVersionWorkflowResultLogs.stream().filter(o -> Objects.equals(o.getImportStatus(), 1)).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(collect)) {
                                //其有对应的父级目录创建失败（先创建父级菜单目录）
                                //先排序，让菜单的顺序一样
                                Long newRootId = 0L;
                                List<RealTimeTaskMenuAndTaskDto> dataList = otherWorkFlows.stream().sorted(Comparator.comparing(RealTimeTaskMenuAndTaskDto::getId)).collect(Collectors.toList());
                                for (RealTimeTaskMenuAndTaskDto otherWorkFlow : dataList) {
                                    //根目录
                                    if (!Objects.equals(2, otherWorkFlow.getMenuType())) {
                                        if (null == otherWorkFlow.getNewId()) {
                                            try {
                                                RealTimeTaskMenuAndTaskDto parent = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                                if (parent == null) {
                                                    otherWorkFlow.setNewParentId(0);
                                                } else {
                                                    otherWorkFlow.setNewParentId(parent.getNewId().intValue());
                                                }
                                                RealTimeTaskMenuVO one = addRootRealWorkMenuDto(otherWorkFlow, uploadVersionLog.getProcId());
                                                //重置新的id
                                                otherWorkFlow.setNewProcId(uploadVersionLog.getProcId());


                                                otherWorkFlow.setNewId(Long.valueOf(one.getId()));
                                                uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), Long.valueOf(otherWorkFlow.getId()), null, Long.valueOf(one.getId()), 0, "");
                                            } catch (Exception e) {
                                                errorFlage = 1;
                                                //创建根目录异常
                                                log.error("生成目录失败！error:{}", e.getMessage());
                                                //这个根目录下的所有的工作流全部失败
                                                Map<String, String> restMsgList = new HashMap<>();
                                                restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                                uploadVersionWorkflowResultLogMapper.updateStatusByRootId(uploadVersionLog.getId(), null, 1, JSON.toJSONString(restMsgList));
                                                if (CollectionUtil.isNotEmpty(workFlows)) {
                                                    for (RealTimeTaskMenuAndTaskDto realTimeTaskMenuAndTaskDto : workFlows) {
                                                        uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), Long.valueOf(realTimeTaskMenuAndTaskDto.getId()), null, null, 1, JSON.toJSONString(restMsgList));

                                                    }
                                                }
                                                //直接跳出循环
                                                break;
                                            }
                                        } else {
                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLog.getId(), Long.valueOf(otherWorkFlow.getId()), null, otherWorkFlow.getNewId(), 0, "");
                                        }
                                    }
                                }
                            }
                        }

                        //如果生成父级菜单目录还是失败，则还是不能生成下面的工作流和工作流依赖
                        String errMsg = "";
                        Integer importType = uploadVersionWorkflowResultLog.getImportType();
                        if (Objects.equals(importType, 3)) {
                            errMsg = "重试导入实时任务失败！";
                        }
                        if (Objects.equals(1, errorFlage)) {
                            throw new RRException(errMsg);
                        }

                        //导入状态  0：成功  1：失败  2：待导入  3：导入中
                        Integer importStatus = 0;
                        Map<String, String> restMsgList = new HashMap<>();
                        RealTimeTaskMenuAndTaskDto workMenuAndLayDto = packWorkMenuAndLayDtoList.stream().filter(o -> Objects.equals(o.getId(), uploadVersionWorkflowResultLog.getOlderWorkflowDataId().intValue())).findAny().orElse(null);
                        if (null == workMenuAndLayDto) {
                            throw new RRException("未找到创建项！");
                        }

                        //导入开始
                        uploadVersionWorkflowResultLogMapper.updateStatusAndMsgById(uploadVersionWorkflowResultLog.getId(), ImportStatusEnum.IMPORT_ING.getId(), "");
                        Long newJobId = 0L;
                        //Integer isExit = 0;
                        if (Objects.equals(importType, 3)) {
                            if (null == workMenuAndLayDto.getNewId()) {
                                //新增节点信息

                                RealTimeTaskMenuAndTaskDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), workMenuAndLayDto.getParentId())).findAny().orElse(null);
                                if (parentWorkMenuAndLayDto != null) {
                                    workMenuAndLayDto.setNewParentId(parentWorkMenuAndLayDto.getNewId().intValue());
                                } else {
                                    workMenuAndLayDto.setNewParentId(0);
                                }
                                RealTimeTaskMenuVO one = addRootRealWorkMenuDto(workMenuAndLayDto, uploadVersionLog.getProcId());
                                //重置新的id
                                workMenuAndLayDto.setNewProcId(uploadVersionLog.getProcId());

                                workMenuAndLayDto.setNewId(Long.valueOf(one.getId()));
                                try {
                                    genNewNodeConfig(versionZipDto, uploadVersionLog.getProcId(), uploadVersionWorkflowResultLog.getId(), workMenuAndLayDto);
                                } catch (Exception e) {
                                    log.error("生成实时任务:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    realTimeTaskMenuMapper.deleteById(one.getId());
                                    realTimeTaskMapper.delete(new QueryWrapper<RealTimeTask>().eq("menu_id", one.getId()));
                                    importStatus = 1;
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "创建失败error:" + e.getMessage());
                                }
                            } else {
                                try {
                                    //编辑作业流（id不能变，删除原有节点配置再新建）
                                    deleteAllInfoByRealWorkMenuId(workMenuAndLayDto.getNewId());

                                    genNewNodeConfig(versionZipDto, uploadVersionLog.getProcId(), uploadVersionWorkflowResultLog.getId(), workMenuAndLayDto);
                                } catch (Exception e) {
                                    log.error("生成实时任务:{}异常error:{}", workMenuAndLayDto.getName(), e.getMessage());
                                    importStatus = 1;
                                    realTimeTaskMenuMapper.deleteById(workMenuAndLayDto.getNewId());
                                    realTimeTaskMapper.delete(new QueryWrapper<RealTimeTask>().eq("menu_id", workMenuAndLayDto.getNewId()));
                                    restMsgList.put(uploadVersionWorkflowResultLog.getWorkflowMenuName(), "修改失败error:" + e.getMessage());
                                }
                            }
                        }
                        //uploadVersionWorkflowResultLogMapper.updateIsExitById(null == uploadVersionWorkflowResultLog ?  null : uploadVersionWorkflowResultLog.getId(),isExit);

                        //导入工作流完成
                        uploadVersionWorkflowResultLogMapper.updateStatusAndJobByName(uploadVersionLog.getId(),
                                Long.valueOf(workMenuAndLayDto.getId()),
                                uploadVersionWorkflowResultLog.getWorkflowMenuName(),
                                importStatus,
                                2,
                                newJobId,
                                JSON.toJSONString(restMsgList));
                        if (1 == importStatus) {
                            throw new RRException(errMsg);
                        }
                    }
                }
            }
        }
    }


    private List<JobInfoDto> initAllCreateJobByProcId(List<WorkMenuAndLayDto> otherWorkFlows, Long olderRootId, Long uploadVersionLogId) {
        List<JobInfoDto> rest = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(otherWorkFlows)) {
            List<WorkMenuAndLayDto> jobs = otherWorkFlows.stream().filter(o -> Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(jobs)) {
                //查询到所有的工作流
                List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs = uploadVersionWorkflowResultLogMapper
                        .selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                .eq("upload_version_log_id", uploadVersionLogId).eq("older_root_id", olderRootId).eq("import_type", 0));
                for (WorkMenuAndLayDto jobWorkInfo : jobs) {
                    JobInfoDto jobInfoDto = jobWorkInfo.getJobInfoDto();
                    if (null != jobInfoDto) {
                        if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                            UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog = uploadVersionWorkflowResultLogs.stream().filter(o -> Objects.equals(o.getOlderWorkflowDataId(), jobWorkInfo.getId())).findAny().orElse(null);
                            if (null != uploadVersionWorkflowResultLog &&
                                    !Objects.equals(uploadVersionWorkflowResultLog.getNewJobId(), null) &&
                                    !Objects.equals(uploadVersionWorkflowResultLog.getNewJobId(), 0L)) {
                                jobInfoDto.setNewId(uploadVersionWorkflowResultLog.getNewJobId().intValue());
                            } else {
                                //这个工作流未生成
                                jobInfoDto.setIsGenError(1);
                            }
                        }
                        rest.add(jobInfoDto);
                    }
                }
            }
        }
        return rest;
    }

    public void importWorkflowsSteps(VersionZipDto versionZipDto, Integer procId, Long uploadVersionLogId, Integer importChangeRole, List<UploadVersionWorkflowResultLogDto> uploadVersionWorkflowResultLogDtos) {
        //打包数据,封装变化的数据
        //当前租户对应的数据源
        Integer tenantId = ShiroUtils.getTenantId();
        List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
        List<RealTimeTaskMenuAndTaskDto> realWorkMenuList = versionZipDto.getRealWorkMenuList();
        if (CollectionUtil.isEmpty(workMenuList) && CollectionUtil.isEmpty(realWorkMenuList)) {
            return;
        }
        //查询到当前工程下对应的菜单
        List<WorkMenu> newWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
        packNewTmpPathName(newWorkMenus);//新的所有路径的名称
        //按照根菜单进行名字查找看是否存在。当前工程下
        List<List<WorkMenuAndLayDto>> packWorkMenuAndLayDtoLists = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            //一层一层来生成
            Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = workMenuList.stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
            //根目录排序
            TreeMap<Long, List<WorkMenuAndLayDto>> sortOlderWorkMenuMaps = MapUtil.sort(olderWorkMenuMaps, Long::compareTo);

            for (Map.Entry<Long, List<WorkMenuAndLayDto>> entry : sortOlderWorkMenuMaps.entrySet()) {
                List<WorkMenuAndLayDto> tempList = genPackWorkMenus(entry, newWorkMenus);
                if (CollectionUtil.isNotEmpty(tempList)) {
                    packWorkMenuAndLayDtoLists.add(tempList);
                }
            }
        }
        //根据结果，来生成和修改菜单树和对应的工作流和工作流依赖
        if (CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoLists)) {
            for (List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList : packWorkMenuAndLayDtoLists) {
                //以根目录为单位，进行创建
                List<WorkMenuAndLayDto> workFlowLays = new ArrayList<>();
                List<WorkMenuAndLayDto> workFlows = new ArrayList<>();
                List<WorkMenuAndLayDto> otherWorkFlows = new ArrayList<>();
                packWorkMenuAndLayDtoList.forEach(o -> {
                    if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())) {
                        workFlowLays.add(o);
                    } else if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())) {
                        workFlows.add(o);
                    } else {
                        otherWorkFlows.add(o);
                    }
                });
                try {
                    //生成对应的菜单和对应的工作流和节点
                    Long newRootId = 0L;
                    List<JobInfoDto> jobDtos = new ArrayList<>();
                    if (CollectionUtil.isNotEmpty(otherWorkFlows)) {
                        //先排序，让菜单的顺序一样
                        List<WorkMenuAndLayDto> dataList = otherWorkFlows.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
                        if (workFlows.size() > 0) {
                            //先生成目录
                            for (WorkMenuAndLayDto otherWorkFlow : dataList) {
                                //根目录
                                if (Objects.equals(0L, otherWorkFlow.getParentId())) {
                                    if (null == otherWorkFlow.getNewId()) {
                                        try {
                                            WorkMenu one = addRootWorkMenuDto(otherWorkFlow, procId);

                                            //重置新的id
                                            otherWorkFlow.setNewRootId(one.getId());
                                            otherWorkFlow.setNewProcId(Long.valueOf(procId));
                                            otherWorkFlow.setNewParentId(0L);
                                            otherWorkFlow.setNewId(one.getId());
                                            newRootId = one.getId();

                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, otherWorkFlow.getId(), otherWorkFlow.getRootId(), one.getId(), 0, "");

                                        } catch (Exception e) {
                                            //创建根目录异常
                                            log.error("生成根目录失败！error:{}", e.getMessage());
                                            //这个根目录下的所有的工作流全部失败
                                            Map<String, String> restMsgList = new HashMap<>();
                                            restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                            uploadVersionWorkflowResultLogMapper.updateStatusByRootId(uploadVersionLogId, otherWorkFlow.getRootId(), 1, JSON.toJSONString(restMsgList));
                                            //直接跳出循环
                                            break;
                                        }
                                    } else {
                                        newRootId = otherWorkFlow.getNewRootId();
                                        uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, otherWorkFlow.getId(), otherWorkFlow.getRootId(), otherWorkFlow.getNewId(), 0, "");
                                    }
                                }
                                //子目录 或者 作业流血缘管理文件夹
                                if (Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.SUB_DIR.getCode())
                                        || Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT.getCode())
                                        || Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.SUB_SUB_DIR.getCode())) {
                                    if (null == otherWorkFlow.getNewId()) {
                                        try {
                                            WorkMenuAndLayDto workMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                            WorkMenu subOne = addWorkFlowMGTAndSubDto(otherWorkFlow, procId, workMenuAndLayDto.getNewId(), newRootId);

                                            //重置新的id
                                            otherWorkFlow.setNewRootId(subOne.getRootId());
                                            otherWorkFlow.setNewProcId(Long.valueOf(procId));
                                            otherWorkFlow.setNewParentId(workMenuAndLayDto.getNewId());
                                            otherWorkFlow.setNewId(subOne.getId());

                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, otherWorkFlow.getId(), otherWorkFlow.getRootId(), subOne.getId(), 0, "");

                                        } catch (Exception e) {
                                            //创建目录异常
                                            log.error("生成目录失败！error:{}", e.getMessage());
                                            //这个目录下的所有的工作流全部失败
                                            Map<String, String> restMsgList = new HashMap<>();
                                            restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                            uploadVersionWorkflowResultLogMapper.updateStatusByRootId(uploadVersionLogId, otherWorkFlow.getRootId(), 1, JSON.toJSONString(restMsgList));
                                            //直接跳出循环
                                            break;
                                        }
                                    } else {
                                        uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, otherWorkFlow.getId(), otherWorkFlow.getRootId(), otherWorkFlow.getNewId(), 0, "");
                                    }
                                }

                            }

                            //作业流文件夹
                            //先排序，让菜单的顺序一样
                            List<WorkMenuAndLayDto> workDataList = workFlows.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
                            for (WorkMenuAndLayDto otherWorkFlow : workDataList) {
                                if (Objects.equals(otherWorkFlow.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())) {
                                    Long finalNewRootId = newRootId;
                                    try {
                                        //先生成文件夹，再生成节点，在生成工作流，再启动任务
                                        UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = uploadVersionWorkflowResultLogDtos.stream().filter(o -> Objects.equals(o.getOlderWorkflowDataId(), otherWorkFlow.getId())).findAny().orElse(null);
                                        if (null != uploadVersionWorkflowResultLogDto) {
                                            UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog = uploadVersionWorkflowResultLogMapper.selectOne(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                                    .eq("upload_version_log_id", uploadVersionLogId)
                                                    .eq("older_workflow_data_id", otherWorkFlow.getId())
                                                    .eq("workflow_menu_name", uploadVersionWorkflowResultLogDto.getWorkflowMenuName()));

                                            long startTime = System.currentTimeMillis();
                                            //开始导入工作流
                                            uploadVersionWorkflowResultLogMapper.updateStatusByName(uploadVersionLogId, otherWorkFlow.getId(), uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), 3, 0, "");
                                            //导入状态  0：成功  1：失败  2：待导入  3：导入中
                                            Integer importStatus = 0;
                                            Map<String, String> restMsgList = new HashMap<>();
                                            //保存新的jobId用于生成作业流依赖
                                            JobInfoDto jobInfoDto = otherWorkFlow.getJobInfoDto();
                                            Long logId = null;
                                            if (null != uploadVersionWorkflowResultLog) {
                                                logId = uploadVersionWorkflowResultLog.getId();
                                            }
                                            Integer isExit = 0;
                                            try {
                                                WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                                if (null == otherWorkFlow.getNewId()) {
                                                    //新增作业流和其任务和对应的节点和配置信息(直接新增)
                                                    try {
                                                        genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto, otherWorkFlow, procId, finalNewRootId, versionZipDto, jobInfoDto, null, null, null, null, logId, tenantId);
                                                    } catch (Exception e) {
                                                        log.error("生成工作流:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                                        importStatus = 1;
                                                        restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "创建失败error:" + e.getMessage());
                                                    }
                                                } else {
                                                    isExit = 1;
                                                    //编辑作业流（id不能变，其如果依赖作业流依赖，还得先停掉作业流依赖，然后重新生成作业流，然后重新保存对应的作业流依赖）
                                                    List<JobNodeInfo> olderJobNodeInfos = new ArrayList<>();
                                                    WorkMenu workMenuLay = new WorkMenu();
                                                    Integer jobId = deleteAllInfoByWorkMenuId(otherWorkFlow.getNewId(), olderJobNodeInfos, workMenuLay);
                                                    jobInfoDto.setNewId(jobId);
                                                    try {
                                                        genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto, otherWorkFlow, procId, finalNewRootId, versionZipDto, jobInfoDto, olderJobNodeInfos, otherWorkFlow.getNewId(), jobId, workMenuLay.getId(), logId, tenantId);
                                                    } catch (Exception e) {
                                                        log.error("生成工作流:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                                        importStatus = 1;
                                                        restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "修改失败error:" + e.getMessage());
                                                    }
                                                }
                                            } catch (Exception e) {
                                                importStatus = 1;
                                                restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "生成失败error:" + e.getMessage());
                                            }
                                            if (null != uploadVersionWorkflowResultLog) {
                                                uploadVersionWorkflowResultLogMapper.updateIsExitById(uploadVersionWorkflowResultLog.getId(), isExit);
                                            }

                                            long endTime = System.currentTimeMillis();
                                            log.info("工作流的执行时间：开始时间：{},结束时间：{},时间差：{}", startTime, endTime, endTime - startTime);

                                            jobDtos.add(jobInfoDto);
                                            //导入工作流完成
                                            uploadVersionWorkflowResultLogMapper.updateStatusAndJobByName(uploadVersionLogId,
                                                    otherWorkFlow.getId(),
                                                    uploadVersionWorkflowResultLogDto.getWorkflowMenuName(),
                                                    importStatus,
                                                    1,
                                                    jobInfoDto.getNewId() == null ? null : Long.valueOf(jobInfoDto.getNewId()),
                                                    JSON.toJSONString(restMsgList));
                                        }
                                    } catch (Exception e) {
                                        log.error("未知异常导致的导入工作流问题：error:{}", e.getMessage());
                                    }
                                }
                            }
                        }
                    }

                    //生成对应的作业流依赖
                    if (CollectionUtil.isNotEmpty(workFlowLays)) {
                        //生成作业流依赖
                        WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT.getCode())).findAny().orElse(null);
                        //先排序，让菜单的顺序一样
                        List<WorkMenuAndLayDto> workFlowList = workFlowLays.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
                        for (WorkMenuAndLayDto otherWorkFlow : workFlowList) {
                            //先生成文件夹，再生成配置信息，再配置作业流依赖，再启动作业流依赖
                            UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = uploadVersionWorkflowResultLogDtos.stream().filter(o -> Objects.equals(o.getOlderWorkflowDataId(), otherWorkFlow.getId())).findAny().orElse(null);
                            if (null != uploadVersionWorkflowResultLogDto) {
                                UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog = uploadVersionWorkflowResultLogMapper.selectOne(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                        .eq("upload_version_log_id", uploadVersionLogId)
                                        .eq("older_workflow_data_id", otherWorkFlow.getId())
                                        .eq("workflow_menu_name", uploadVersionWorkflowResultLogDto.getWorkflowMenuName()));
                                long startTime = System.currentTimeMillis();
                                //开始导入工作流
                                uploadVersionWorkflowResultLogMapper.updateStatusByName(uploadVersionLogId, otherWorkFlow.getId(), uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), 3, 0, "");
                                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                                Integer importStatus = 0;
                                Map<String, String> restMsgList = new HashMap<>();
                                StringBuilder stringBuilder = new StringBuilder();
                                Long workDepId = 0L;
                                Long logId = null;
                                if (null != uploadVersionWorkflowResultLog) {
                                    logId = uploadVersionWorkflowResultLog.getId();
                                }
                                Integer isExit = 0;
                                //生成作业流依赖
                                if (null == otherWorkFlow.getNewId()) {
                                    try {
                                        genWorkFlowLayAndConfig(parentWorkMenuAndLayDto, otherWorkFlow, procId, newRootId, jobDtos, null, null, logId);
                                        workDepId = otherWorkFlow.getWorkFlowDepDto().getNewId();
                                    } catch (Exception e) {
                                        log.error("生成工作流依赖:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                        importStatus = 1;
                                        stringBuilder.append(e.getMessage());
                                        //先删除后新增
                                        deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
                                    }
                                } else {
                                    isExit = 1;
                                    //先删除后新增
                                    workDepId = deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
                                    try {
                                        genWorkFlowLayAndConfig(parentWorkMenuAndLayDto, otherWorkFlow, procId, newRootId, jobDtos, otherWorkFlow.getNewId(), workDepId, logId);
                                    } catch (Exception e) {
                                        log.error("生成工作流依赖:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                        importStatus = 1;
                                        stringBuilder.append(e.getMessage());
                                    }
                                }
                                if (null != uploadVersionWorkflowResultLog) {
                                    uploadVersionWorkflowResultLogMapper.updateIsExitById(uploadVersionWorkflowResultLog.getId(), isExit);
                                }
                                restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "生成失败error:" + stringBuilder.toString());
                                long endTime = System.currentTimeMillis();
                                log.info("工作流依赖的执行时间：开始时间：{},结束时间：{},时间差：{}", startTime, endTime, endTime - startTime);
                                //导入工作流完成
                                uploadVersionWorkflowResultLogMapper.updateStatusAndJobByName(uploadVersionLogId,
                                        otherWorkFlow.getId(),
                                        uploadVersionWorkflowResultLogDto.getWorkflowMenuName(),
                                        importStatus,
                                        1,
                                        workDepId,
                                        JSON.toJSONString(restMsgList));
                            }
                        }
                    }
                } catch (Exception e) {
                    log.error("ggg--工作流--ggg创建失败！error:{}", e.getMessage());

                    //删除这个新的改变（回滚）
//                    deleteAllInfoByRootWorkMenuId(packWorkMenuAndLayDtoList);
                }
            }
        }
        //查询到当前工程下对应的实时任务菜单
        List<RealTimeTaskMenu> newRealWorkMenus = realTimeTaskMenuMapper.selectList(new QueryWrapper<RealTimeTaskMenu>().eq("proc_id", procId).eq("state", 1));
        packNewRealTmpPathName(newRealWorkMenus);
        //按照根菜单进行名字查找看是否存在。当前工程下
        List<List<RealTimeTaskMenuAndTaskDto>> packRealWorkMenuAndLayDtoLists = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(realWorkMenuList)) {
            List<RealTimeTaskMenuAndTaskDto> olderRootWorkMenuLists = realWorkMenuList.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
            for (RealTimeTaskMenuAndTaskDto entry : olderRootWorkMenuLists) {
                List<RealTimeTaskMenuAndTaskDto> tempList = genPackRealWorkMenus(entry.getId(), realWorkMenuList, newRealWorkMenus);
                if (CollectionUtil.isNotEmpty(tempList)) {
                    packRealWorkMenuAndLayDtoLists.add(tempList);
                }
            }
        }
        //根据结果，来生成和修改菜单树和对应的工作流和工作流依赖
        if (CollectionUtil.isNotEmpty(packRealWorkMenuAndLayDtoLists)) {
            for (List<RealTimeTaskMenuAndTaskDto> packRealWorkMenuAndLayDtoList : packRealWorkMenuAndLayDtoLists) {
                //以根目录为单位，进行创建
                List<RealTimeTaskMenuAndTaskDto> otherWorkFlows = new ArrayList<>();
                List<RealTimeTaskMenuAndTaskDto> workFlows = new ArrayList<>();
                packRealWorkMenuAndLayDtoList.forEach(o -> {
                    if (o.getMenuType() == 2) {
                        workFlows.add(o);
                    } else {
                        otherWorkFlows.add(o);
                    }
                });
                boolean rootIsCreat = true;
                try {
                    //生成对应的菜单和对应的工作流和节点
                    if (CollectionUtil.isNotEmpty(otherWorkFlows) || CollectionUtil.isNotEmpty(workFlows)) {
                        //先排序，让菜单的顺序一样
                        List<RealTimeTaskMenuAndTaskDto> dataList = otherWorkFlows.stream().sorted(Comparator.comparing(RealTimeTaskMenuAndTaskDto::getId)).collect(Collectors.toList());
                        //工作流的菜单
                        if (workFlows.size() > 0) {
//                            final CountDownLatch latch = new CountDownLatch(count.intValue());
                            for (RealTimeTaskMenuAndTaskDto otherWorkFlow : dataList) {
                                //实时任务目录
                                if (!Objects.equals(2, otherWorkFlow.getMenuType())) {
                                    if (null == otherWorkFlow.getNewId()) {
                                        try {
                                            RealTimeTaskMenuAndTaskDto parent = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                            if (parent == null) {
                                                otherWorkFlow.setNewParentId(0);
                                            } else {
                                                otherWorkFlow.setNewParentId(parent.getNewId().intValue());
                                            }
                                            RealTimeTaskMenuVO one = addRootRealWorkMenuDto(otherWorkFlow, procId);
                                            //重置新的id
                                            otherWorkFlow.setNewProcId(procId);
                                            otherWorkFlow.setNewId(Long.valueOf(one.getId()));
                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, Long.valueOf(otherWorkFlow.getId()), null, Long.valueOf(one.getId()), 0, "");
                                        } catch (Exception e) {
                                            rootIsCreat = false;
                                            //创建根目录异常
                                            log.error("生成目录失败！error:{}", e.getMessage());
                                            //这个根目录下的所有的工作流全部失败
                                            Map<String, String> restMsgList = new HashMap<>();
                                            restMsgList.put(otherWorkFlow.getName(), "生成失败error:" + e.getMessage());
                                            uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, Long.valueOf(otherWorkFlow.getId()), null, null, 1, JSON.toJSONString(restMsgList));
                                            if (CollectionUtil.isNotEmpty(workFlows)) {
                                                for (RealTimeTaskMenuAndTaskDto realTimeTaskMenuAndTaskDto : workFlows) {
                                                    uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, Long.valueOf(realTimeTaskMenuAndTaskDto.getId()), null, null, 1, JSON.toJSONString(restMsgList));

                                                }
                                            }
                                            //直接跳出循环
                                            break;
                                        }
                                    } else {
                                        uploadVersionWorkflowResultLogMapper.updateStatusById(uploadVersionLogId, Long.valueOf(otherWorkFlow.getId()), null, otherWorkFlow.getNewId(), 0, "");
                                    }
                                }
                            }
                            if (rootIsCreat) {
                                //实时任务
                                //先排序，让菜单的顺序一样
                                List<RealTimeTaskMenuAndTaskDto> workDataList = workFlows.stream().sorted(Comparator.comparing(RealTimeTaskMenuAndTaskDto::getId)).collect(Collectors.toList());
                                for (RealTimeTaskMenuAndTaskDto otherWorkFlow : workDataList) {
                                    try {
                                        //先生成实时任务再生成节点相关配置
                                        UploadVersionWorkflowResultLogDto uploadVersionWorkflowResultLogDto = uploadVersionWorkflowResultLogDtos.stream().filter(o -> Objects.equals(o.getOlderWorkflowDataId().intValue(), otherWorkFlow.getId())).findAny().orElse(null);
                                        if (null != uploadVersionWorkflowResultLogDto) {
                                            UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog = uploadVersionWorkflowResultLogMapper.selectOne(new QueryWrapper<UploadVersionWorkflowResultLog>()
                                                    .eq("upload_version_log_id", uploadVersionLogId)
                                                    .eq("older_workflow_data_id", otherWorkFlow.getId())
                                                    .eq("workflow_menu_name", uploadVersionWorkflowResultLogDto.getWorkflowMenuName()));

                                            long startTime = System.currentTimeMillis();
                                            //开始导入实时任务
                                            uploadVersionWorkflowResultLogMapper.updateStatusByName(uploadVersionLogId, Long.valueOf(otherWorkFlow.getId()), uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), 3, 0, "");
                                            //导入状态  0：成功  1：失败  2：待导入  3：导入中
                                            Integer importStatus = 0;
                                            Map<String, String> restMsgList = new HashMap<>();
                                            //保存新的jobId用于生成作业流依赖
                                            RealTimeTaskVO jobInfoDto = otherWorkFlow.getRealTimeTaskVO();
                                            Long logId = null;
                                            if (null != uploadVersionWorkflowResultLog) {
                                                logId = uploadVersionWorkflowResultLog.getId();
                                            }
                                            Integer isExit = 0;
                                            try {
                                                RealTimeTaskMenuAndTaskDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
                                                if (null == otherWorkFlow.getNewId()) {
                                                    if (parentWorkMenuAndLayDto != null) {
                                                        otherWorkFlow.setNewParentId(parentWorkMenuAndLayDto.getNewId().intValue());
                                                    } else {
                                                        otherWorkFlow.setNewParentId(0);
                                                    }
                                                    RealTimeTaskMenuVO one = addRootRealWorkMenuDto(otherWorkFlow, procId);
                                                    //重置新的id
                                                    otherWorkFlow.setNewProcId(procId);

                                                    otherWorkFlow.setNewId(Long.valueOf(one.getId()));
                                                    //新增节点信息
                                                    try {
                                                        genNewNodeConfig(versionZipDto, procId, logId, otherWorkFlow);
                                                    } catch (Exception e) {
                                                        log.error("生成实时任务:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                                        importStatus = 1;
                                                        realTimeTaskMenuMapper.deleteById(one.getId());
                                                        realTimeTaskMapper.delete(new QueryWrapper<RealTimeTask>().eq("menu_id", one.getId()));
                                                        restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "创建失败error:" + e.getMessage());
                                                    }
                                                } else {
                                                    isExit = 1;
                                                    //编辑作业流（id不能变，删除原有节点配置再新建）
                                                    deleteAllInfoByRealWorkMenuId(otherWorkFlow.getNewId());
                                                    try {
                                                        genNewNodeConfig(versionZipDto, procId, logId, otherWorkFlow);
                                                    } catch (Exception e) {
                                                        log.error("生成实时任务:{}异常error:{}", otherWorkFlow.getName(), e.getMessage());
                                                        importStatus = 1;
                                                        realTimeTaskMenuMapper.deleteById(otherWorkFlow.getNewId());
                                                        realTimeTaskMapper.delete(new QueryWrapper<RealTimeTask>().eq("menu_id", otherWorkFlow.getNewId()));
                                                        restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "修改失败error:" + e.getMessage());
                                                    }
                                                }
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                                importStatus = 1;
                                                restMsgList.put(uploadVersionWorkflowResultLogDto.getWorkflowMenuName(), "生成失败error:" + e.getMessage());
                                            }
                                            if (null != uploadVersionWorkflowResultLog) {
                                                uploadVersionWorkflowResultLogMapper.updateIsExitById(uploadVersionWorkflowResultLog.getId(), isExit);
                                            }

                                            long endTime = System.currentTimeMillis();
                                            log.info("实时任务的执行时间：开始时间：{},结束时间：{},时间差：{}", startTime, endTime, endTime - startTime);

                                            //导入工作流完成
                                            uploadVersionWorkflowResultLogMapper.updateStatusAndJobByName(uploadVersionLogId,
                                                    Long.valueOf(otherWorkFlow.getId()),
                                                    uploadVersionWorkflowResultLogDto.getWorkflowMenuName(),
                                                    importStatus,
                                                    2,
                                                    otherWorkFlow.getNewId() == null ? null : Long.valueOf(otherWorkFlow.getNewId()),
                                                    JSON.toJSONString(restMsgList));
                                        }
                                    } catch (Exception e) {
                                        log.error("未知异常导致的导入实时任务问题：error:{}", e.getMessage());
                                    }
                                }
                            }
                        }
                    }


                } catch (Exception e) {
                    log.error("ggg--实时任务--ggg创建失败！error:{}", e.getMessage());

                }
            }
        }
    }

    private void genNewNodeConfig(VersionZipDto versionZipDto, Integer procId, Long logId, RealTimeTaskMenuAndTaskDto otherWorkFlow) {
        uploadVersionWorkflowResultLogMapper.updateWorkMenuId(otherWorkFlow.getNewId(), logId);
        RealTimeTask realTimeTask = realTimeTaskMapper.selectOne(new QueryWrapper<RealTimeTask>().eq("menu_id", otherWorkFlow.getNewId()));
        if (realTimeTask != null) {
            RealTimeTaskVO realTimeTaskVO = otherWorkFlow.getRealTimeTaskVO();
            if (realTimeTaskVO.getTaskType().equals(Constant.RealTimeTaskType.FLINK_SQL.getCode()) || realTimeTaskVO.getTaskType().equals(Constant.RealTimeTaskType.FLINK_SQL_DAG.getCode())) {
                List<FlinkTaskNodeVO> jobNodeInfos = realTimeTaskVO.getNodeList();
                if (CollectionUtil.isEmpty(jobNodeInfos)) {
                    return;
                }
                for (FlinkTaskNodeVO jobNodeInfo : jobNodeInfos) {
                    if (Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.source.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kafka.getId())
                            || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kudu.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.hive.getId())) {
                        JSONObject config = jobNodeInfo.getConfig();
                        if (config != null) {
                            //对应的输入输出表是否存在和是否关联到当前这个工程
                            if (StringUtils.isNotEmpty(jobNodeInfo.getTableName())) {
                                String dbName = config.getString("dataBase");
                                if (Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.source.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kafka.getId())) {
                                    BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectOne(new QueryWrapper<BdpRealTableInfo>().eq("db_name", dbName).eq("table_name", jobNodeInfo.getTableName()));
                                    if (null == tableInfo) {
                                        throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点,实时表：【" + dbName + "." + jobNodeInfo.getTableName() + "】不存在！" + "验证不通过！");
                                    } else {
                                        ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 2));
                                        if (null == procTable) {
                                            throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点,实时表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                        }
                                    }
                                } else {
                                    TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", dbName).eq("table_name", jobNodeInfo.getTableName()));
                                    if (null == tableInfo) {
                                        throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点,输出离线表：【" + dbName + "." + jobNodeInfo.getTableName() + "】不存在！" + "验证不通过！");
                                    } else {
                                        ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 1));
                                        if (null == procTable) {
                                            throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点,输出离线表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (realTimeTaskVO.getTaskType().equals(Constant.RealTimeTaskType.REAL_TIME_COLLECTION.getCode())) {
                JSONObject config = realTimeTaskVO.getConfig();
                if (config != null) {
                    String dbName = config.getString("targetDbname");
                    String tableName = config.getString("targetTableName");
                    Integer connectId = config.getInteger("resourceId");
                    //验证连接id
                    List<ConfConnectAndConfigDto> connectList = versionZipDto.getConnectList();
                    if (CollectionUtil.isEmpty(connectList)) {
                        throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,其版本包中接入数据源为空,验证不通过！");
                    } else {
                        ConfConnectAndConfigDto confConnectAndConfigDto = null;
                        confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(connectId, o.getId())).findAny().orElse(null);
                        if (null == confConnectAndConfigDto) {
                            throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,其版本包中接入数据源未关联项目,验证不通过！");
                        } else {
                            //直接改为按照名字进行数据源确认
                            List<ConfConnect> confConnect = confConnectMapper.selectList(new QueryWrapper<ConfConnect>()
                                    .eq("name", confConnectAndConfigDto.getName()).eq("tenant_id",ShiroUtils.getTenantId())
                            );
                            if (CollectionUtil.isEmpty(confConnect)) {
                                throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,当前系统数据源【" + confConnectAndConfigDto.getName() + "】不存在,验证不通过！");
                            } else {
                                List<Integer> connectIds=confConnect.stream().map(i->i.getId()).collect(Collectors.toList());
                                //数据源连接是否已经关联
                                List<ProcConnect> procConnect = procConnectMapper.selectList(new QueryWrapper<ProcConnect>().eq("proc_id", procId).in("connect_id", connectIds));
                                if (CollectionUtil.isEmpty( procConnect)) {
                                    throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,当前系统数据源【" + confConnectAndConfigDto.getName() + "】未关联项目,验证不通过！");
                                } else {
                                    //验证输出表是否存在以及是否关联到项目
                                    TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", dbName).eq("table_name", tableName));
                                    if (null == tableInfo) {
                                        throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,输出表：【" + dbName + "." + tableName + "】不存在！" + "验证不通过！");
                                    } else {
                                        ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 1));
                                        if (null == procTable) {
                                            throw new RRException("【" + otherWorkFlow.getName() + "】下的【" + realTimeTaskVO.getTaskName() + "】任务,输出表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                        }
                                    }
                                }
                            }

                        }

                    }
                }
            }
            List<FlinkTaskNodeVO> nodes = realTimeTaskVO.getNodeList();
            if (CollectionUtil.isNotEmpty(nodes)) {
                for (FlinkTaskNodeVO nodeVO : nodes) {
                    nodeVO.setTaskId(otherWorkFlow.getNewId().intValue());
                    nodeVO.setOlderId(nodeVO.getId());
                    nodeVO.setId(null);
                    try {
                        flinkTaskNodeService.saveNode(nodeVO);
                    } catch (Exception e) {
                        throw new RRException(e.getMessage());
                    }
                }
                List<FlinkNodeUnion> unions = otherWorkFlow.getLineList();
                if (CollectionUtil.isNotEmpty(unions)) {
                    List<FlinkNodeUnion> edges = new ArrayList<>();
                    for (FlinkNodeUnion jobLink : unions) {
                        FlinkTaskNodeVO from = nodes.stream().filter(o -> Objects.equals(o.getOlderId(), jobLink.getNodeFrom())).findAny().orElse(null);
                        FlinkTaskNodeVO to = nodes.stream().filter(o -> Objects.equals(o.getOlderId(), jobLink.getNodeTo())).findAny().orElse(null);
                        if (null == from || null == to) {
                            throw new RRException("源：【" + jobLink.getNodeFrom() + "】或者目标节点：【" + jobLink.getNodeTo() + "】不存在！");
                        }
                        FlinkNodeUnion jobLinkDto = new FlinkNodeUnion();
                        jobLinkDto.setTaskId(otherWorkFlow.getNewId().intValue());
                        jobLinkDto.setNodeFrom(from.getId());
                        jobLinkDto.setNodeTo(to.getId());
                        jobLinkDto.setWebFrom(jobLink.getWebFrom());
                        jobLinkDto.setWebTo(jobLink.getWebTo());
                        edges.add(jobLinkDto);
                    }
                    flinkNodeUnionMapper.batchInsert(edges);
                }
                List<BdpRealTaskAlarmObject> alarmObjects = otherWorkFlow.getAlarmObjects();
                if (CollectionUtil.isNotEmpty(alarmObjects)) {
                    for (BdpRealTaskAlarmObject alarmObject : alarmObjects) {
                        alarmObject.setObjectId(otherWorkFlow.getNewId().intValue());
                    }
                    realTaskAlarmObjectMapper.batchInsert(alarmObjects);
                }
            }

        }
    }


    private VersionZipDto upAndAnlagZip(Integer procId, String zipPathName, String importAllJson) {
        VersionZipDto versionZipDto = null;
        if (StringUtils.isEmpty(importAllJson)) {
            versionZipDto = getZipData(procId, zipPathName);
            if (null == versionZipDto) {
                log.error("上传的版本包解析json异常！");
                throw new RRException("上传的版本包解析json异常！");
            }
        } else {
            versionZipDto = beanDataChangeService.changeJsonToModel(importAllJson, Boolean.TRUE);
        }
        return versionZipDto;
    }

    public void importConnectSteps(VersionZipDto versionZipDto, Integer procId, Long
            uploadVersionLogId, Integer importChangeRole) {
        //关联的数据源 : 用户和连接名字 同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变）
        String zipEnv = versionZipDto.getZipEnv();
        List<ConfConnectAndConfigDto> allConnectList = versionZipDto.getConnectList();
        String activeProfile = SpringContextUtil.getActiveProfile();
        //用户和连接名字 同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变）
        if (CollectionUtil.isNotEmpty(allConnectList)) {
            for (ConfConnectAndConfigDto confConnectAndConfigDto : allConnectList) {
                //查询数据
                UploadVersionConnectResultLog uploadVersionConnectResultLog = uploadVersionConnectResultLogMapper.selectOne(new QueryWrapper<UploadVersionConnectResultLog>()
                        .eq("upload_version_log_id", uploadVersionLogId)
                        .eq("connect_name", confConnectAndConfigDto.getName())
                        .eq("older_connect_data_id", confConnectAndConfigDto.getId()));
                //开始导入
                uploadVersionConnectResultLogMapper.updateStatusByName(uploadVersionLogId, confConnectAndConfigDto.getId(), confConnectAndConfigDto.getName(), 3, "");
                //导入状态  0：成功  1：失败  2：待导入  3：导入中
                Integer importStatus = 0;
                Map<String, String> restMsgList = new HashMap<>();
                Integer connectId = null;
                try {
                    connectId = importConnectInfo(confConnectAndConfigDto, zipEnv, activeProfile, procId, importChangeRole, null == uploadVersionConnectResultLog ? null : uploadVersionConnectResultLog.getId());
                } catch (Exception e) {
                    importStatus = 1;
                    restMsgList.put("【" + confConnectAndConfigDto.getName() + "】数据源", "创建失败！error:" + e.getMessage());
                    log.error("版本导入数据源异常！error:{}", e.getMessage());
                    e.printStackTrace();
                }
                //改变对应的状态
                uploadVersionConnectResultLogMapper.updateStatusAndIdByName(uploadVersionLogId,
                        confConnectAndConfigDto.getId(),
                        confConnectAndConfigDto.getName(),
                        importStatus,
                        connectId,
                        JSON.toJSONString(restMsgList));
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public Integer importConnectInfo(ConfConnectAndConfigDto confConnectAndConfigDto, String zipEnv, String
            activeProfile, Integer procId, Integer importChangeRole, Long connectLogId) {
        Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
        //目前名字全局唯一  添加上租户id
        Integer tenantId = ShiroUtils.getTenantId();
        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                        .eq("name", confConnectAndConfigDto.getName())
                        .eq("tenant_id", tenantId)
                        .last(" limit 1 ")
//                .eq("create_per",userId)
        );
        Integer connectId = null;
        //Integer isExit = 0;
        if (null == confConnect) {
            log.error("数据源连接：【{}】不存在,用户名：{}，用户id:{}", confConnectAndConfigDto.getName(), confConnectAndConfigDto.getCreatePerName(), userId);
            //直接新建,并且关联到这个项目
            connectId = insertOrUpdate(confConnectAndConfigDto, procId, null, userId, tenantId);
            if (null == importChangeRole) {
                //初始化权限
                dataPermissionService.initDataPermission(connectId,
                        PermissionTypeEnum.RESOURCE.getType(), userId, null);
            }
        } else {
            //isExit = 1;
            connectId = confConnect.getId();
            //先删除，再新建id保持不变
            deleteConnects(procId, confConnect.getId());
            insertOrUpdate(confConnectAndConfigDto, procId, confConnect.getId(), userId, tenantId);
            //没有就关联一下
            ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()).last(" limit 1 "));
            if (null == procConnect) {
                procConnect = new ProcConnect();
                procConnect.setConnectId(confConnect.getId());
                procConnect.setProcId(procId);
                procConnectMapper.insert(procConnect);
            }
//            //不管是否是同一个环境，都要先删除后创建
//            if(!Objects.equals(zipEnv, activeProfile)){
//
//            }else{
//
//            }
        }
        //uploadVersionConnectResultLogMapper.updateIsExitById(connectLogId,isExit);
        //创建对应的权限
        if (null != importChangeRole) {
            dataPermissionService.initDataPermission(connectId,
                    PermissionTypeEnum.RESOURCE.getType(), userId, Long.valueOf(importChangeRole));
        }
        return connectId;
    }

    private void backUps(UploadVersionLog uploadVersionLog) {
        //查询是否备份过
        BdpVersion bdpVersion = iBdpVersionService.getOne(new QueryWrapper<BdpVersion>().eq("version_type", VersionType.BACKUPS.getCode()).eq("up_zip_path_name", uploadVersionLog.getZipPathName()));
        if (null != bdpVersion) {
            return;
            //删除数据和删除对应的zip文件
//            deleteVersion(bdpVersion.getId(),uploadVersionLog.getProcId(),bdpVersion.getUpZipPathName());
        }
        //查询到是基于那个版本备份的
        String baseZipPathName = null;
        List<BdpVersion> bdpVersions = bdpVersionMapper.selectByUpZipTime(uploadVersionLog.getProcId(), null);
        if (CollectionUtil.isNotEmpty(bdpVersions)) {
            baseZipPathName = bdpVersions.get(bdpVersions.size() - 1).getUpZipPathName();
        }
        //重新先备份当前工程下所有的数据信息，并且打成zip包 保存起来
        BdpAddVersionDto bdpAddVersionDto = new BdpAddVersionDto();
        LocalDateTime now = LocalDateTime.now();
        String currentTime = TimeUtil.getCurrentTime(now);
        bdpAddVersionDto.setVersionName("auto-" + currentTime);
        bdpAddVersionDto.setVersionNum("auto-V-" + currentTime);
        bdpAddVersionDto.setCreatePer(ShiroUtils.getUserId().intValue());
        bdpAddVersionDto.setVersionType(VersionType.BACKUPS.getCode());
        bdpAddVersionDto.setProcId(uploadVersionLog.getProcId());
        bdpAddVersionDto.setUpZipPathName(uploadVersionLog.getZipPathName());
        bdpAddVersionDto.setIsRock(1);
        bdpAddVersionDto.setCreateTime(now);
        bdpAddVersionDto.setBaseZipPathName(baseZipPathName);
        BdpVersion bdpVersion1 = iBdpVersionService.copyVersion(bdpAddVersionDto);
        //重新先备份当前工程下所有的数据信息，并且上传到hdfs上
        CopyAllDataDto copyAllDataDto = null;
        try {
            copyAllDataDto = listAllCopyData(uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole());
        } catch (Exception e) {
            log.error("解析备份文件异常！error:{}", e.getMessage());
        }
        //上传文件
        HdfsUtil hdfsUtil = null;
        try {
            hdfsUtil = new HdfsUtil(bdpJobConfig);
            String uploadPath = String.format("%s/%s/%s/%s", bdpJobConfig.getVersion(), uploadVersionLog.getProcId(), bdpVersion1.getId(), uploadVersionLog.getZipPathName() + ".json");
            hdfsUtil.writeFile(JSONObject.toJSONString(copyAllDataDto).getBytes("utf-8"), uploadPath);
            hdfsUtil.close();
        } catch (Exception e) {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
            log.error("备份文件异常！error:{}", e.getMessage());
            throw new RRException("备份文件异常！");
        } finally {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
        }
        //保存备份的json信息
        BdpVersionProcRel bdpVersionProcRel = new BdpVersionProcRel();
        bdpVersionProcRel.setVersionId(bdpVersion1.getId());
        bdpVersionProcRel.setProcId(uploadVersionLog.getProcId());
//        bdpVersionProcRel.setAllCopyDataJson(JSONObject.toJSONString(copyAllDataDto));
        bdpVersionProcRelMapper.insert(bdpVersionProcRel);
    }

    private void checkWorkflows(VersionZipDto
                                        versionZipDto, List<UploadVersionAllJsonCheackLogDto> listRest, Long uploadVersionLogId, Integer
                                        procId) {
        List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            //挑选出来所有的工作流
            List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
            filterAllWorkFlowNameAndLayName(workMenuList, allWorkFlowNames, Boolean.FALSE, Boolean.TRUE, null, Boolean.FALSE);
            if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
                //检测对应的工作流下的每一个节点的配置
                for (VersionWorkflowDto allWorkFlowName : allWorkFlowNames) {
                    WorkMenuAndLayDto workMenuAndLayDto = workMenuList.stream().filter(o -> Objects.equals(o.getId(), allWorkFlowName.getOlderId())).findAny().orElse(null);
                    checkJobNodes(versionZipDto, workMenuAndLayDto, allWorkFlowName, listRest, uploadVersionLogId, procId);
                }
            }
        }
    }

    private void checkRealWorkflows(VersionZipDto
                                            versionZipDto, List<UploadVersionAllJsonCheackLogDto> listRest, Long uploadVersionLogId, Integer
                                            procId) {
        List<RealTimeTaskMenuAndTaskDto> workMenuList = versionZipDto.getRealWorkMenuList();
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            //挑选出来所有的实时任务
            List<VersionWorkflowDto> allWorkFlowNames = new ArrayList<>();
            filterAllRealWorkFlowName(workMenuList, allWorkFlowNames, null, Boolean.FALSE);
            if (CollectionUtil.isNotEmpty(allWorkFlowNames)) {
                //检测对应的实时任务下的每一个节点的配置
                for (VersionWorkflowDto allWorkFlowName : allWorkFlowNames) {
                    RealTimeTaskMenuAndTaskDto workMenuAndLayDto = workMenuList.stream().filter(o -> Objects.equals(o.getId(), allWorkFlowName.getOlderId().intValue())).findAny().orElse(null);
                    checkRealTaskNodes(versionZipDto, workMenuAndLayDto, allWorkFlowName, listRest, uploadVersionLogId, procId);
                }
            }
        }
    }

    /***
     * 验证工作流下的节点数据源、仓库表的验证
     * @param versionZipDto
     * @param workMenuAndLayDto
     * @param allWorkFlowName
     * @param listRest
     * @param uploadVersionLogId
     * @param procId
     */
    private void checkJobNodes(VersionZipDto versionZipDto,
                               WorkMenuAndLayDto workMenuAndLayDto,
                               VersionWorkflowDto allWorkFlowName,
                               List<UploadVersionAllJsonCheackLogDto> listRest,
                               Long uploadVersionLogId,
                               Integer procId) {
        if (null == workMenuAndLayDto) {
            addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
            return;
        }
        JobInfoDto jobInfoDto = workMenuAndLayDto.getJobInfoDto();
        if (null == jobInfoDto) {
            addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
            return;
        }
        List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
        if (CollectionUtil.isEmpty(jobNodeInfos)) {
            addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
            return;
        }
        //TODO:hujz 校验是否被作业流依赖引用

        Integer status = 0;
        Map<String, String> restList = new HashMap<>();
        for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
            JobNodeConfig jobNodeConfig = jobNodeInfo.getJobNodeConfig();
            try {
                if (null == jobNodeConfig) {
                    //restList.put("【"+allWorkFlowName.getName()+"】下的【"+jobNodeInfo.getName() + "】节点","无配置信息,验证通过！");
                    continue;
                }
                if (Objects.equals(jobNodeInfo.getTypeId(), JobType.INPUT.getCode()) || Objects.equals(jobNodeInfo.getTypeId(), JobType.OUTPUT.getCode())) {
                    //验证连接id
                    List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
                    if (CollectionUtil.isEmpty(connectList)) {
                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "其版本包中接入数据源未关联项目,验证不通过！");
                        status++;
                        continue;
                    }
                    ConfConnectAndConfigDto confConnectAndConfigDto = null;
                    if (Objects.equals(jobNodeInfo.getTypeId(), JobType.INPUT.getCode())) {
                        confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getInput_connect_id(), o.getId())).findAny().orElse(null);
                    }
                    if (Objects.equals(jobNodeInfo.getTypeId(), JobType.OUTPUT.getCode())) {
                        confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getOutput_connect_id(), o.getId())).findAny().orElse(null);
                    }
                    if (null == confConnectAndConfigDto) {
                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "其版本包中接入数据源未关联项目,验证不通过！");
                        status++;
                        continue;
                    }
//                    Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
                    //直接改为按照名字进行数据源确认
                    ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                                    .eq("name", confConnectAndConfigDto.getName())
                                    .last(" limit 1 ")
//                            .eq("create_per",userId)
//                            .eq("type_id",confConnectAndConfigDto.getTypeId())
                    );
                    if (null == confConnect) {
                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "当前系统数据源【" + confConnectAndConfigDto.getName() + "】不存在,验证不通过！");
                        status++;
                        continue;
                    } else {
                        //数据源连接是否已经关联
                        ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()).last(" limit 1 "));
                        if (null == procConnect) {
                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "当前系统数据源【" + confConnect.getName() + "】未关联项目,验证不通过！");
                            status++;
                            continue;
                        }
                    }
                    //验证接入类型的sap
                    if (Objects.equals(jobNodeInfo.getTypeId(), JobType.INPUT.getCode()) && Objects.equals(confConnect.getTypeId(), ConnectTypeEnum.Sap.getCode())) {
                        //bdp_sap_connect_field 需要改变id
                        SapConnectField sapConnectField = sapConnectFieldMapper.selectOne(new QueryWrapper<SapConnectField>().eq("connect_id", confConnect.getId()));
                        if (null == sapConnectField) {
                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "sap数据源：【" + confConnect.getName() + "】输入参数异常" + ",验证不通过！");
                            status++;
                            continue;
                        }
                        //验证其sap的仓库表是否存在
                        List<String> sap_output_table_name = jobNodeConfig.getSap_output_table_name();
                        if (CollectionUtil.isNotEmpty(sap_output_table_name)) {
                            for (String s : sap_output_table_name) {
                                if (!Objects.equals("[]", s) && StringUtils.isNotEmpty(s)) {
                                    String[] split = s.split("\\.");
                                    if (split.length > 1) {
                                        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
                                        if (null == tableInfo) {
                                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "数据仓库：【" + s + "】不存在" + ",验证不通过！");
                                            status++;
                                            continue;
                                        } else {
                                            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
                                            if (null == procTable) {
                                                restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "数据仓库：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目" + ",验证不通过！");
                                                status++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //验证接入类型的输出仓库
                    if (Objects.equals(jobNodeInfo.getTypeId(), JobType.INPUT.getCode())) {
                        //对应的输出仓库的是否存在和是否关联到当前这个工程
                        if (StringUtils.isNotEmpty(jobNodeConfig.getOutput_db_name()) && StringUtils.isNotEmpty(jobNodeConfig.getOutput_table_name())) {
                            TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", jobNodeConfig.getOutput_db_name()).eq("table_name", jobNodeConfig.getOutput_table_name()));
                            if (null == tableInfo) {
                                restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "数据仓库：【" + jobNodeConfig.getOutput_db_name() + "." + jobNodeConfig.getOutput_table_name() + "】不存在！" + "验证不通过！");
                                status++;
                                continue;
                            } else {
                                ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).last(" limit 1 "));
                                if (null == procTable) {
                                    restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "数据仓库：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                    status++;
                                    continue;
                                }
                            }
                        }
                    }
                }
                if (Objects.equals(jobNodeInfo.getTypeId(), JobType.SQL.getCode())) {
                    //输出表设置
                    List<String> jobOutPutTableNames = jobNodeConfig.getJobOutPutTableNames();
                    if (CollectionUtil.isNotEmpty(jobOutPutTableNames)) {
                        for (int i = 0; i < jobOutPutTableNames.size(); i++) {
                            String s = jobOutPutTableNames.get(i);
                            if (StringUtils.isNotEmpty(s)) {
                                String[] split = s.split("\\.");
                                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
                                if (null == tableInfo) {
                                    restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "数据仓库：【" + s + "】不存在" + ",验证不通过！");
                                    status++;
                                    continue;
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                log.error("{}下的{}节点验证节点异常！error:{}", allWorkFlowName.getName(), jobNodeInfo.getName(), e.getMessage());
                restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getName() + "】节点", "验证异常！" + "验证不通过！");
                status++;
            }
        }
        if (status > 0) {
            status = 1;
        }
        addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 4, status, JSON.toJSONString(restList), listRest, uploadVersionLogId);
    }

    /***
     * 验证实时任务下的节点数据源、实时表的验证
     * @param versionZipDto
     * @param workMenuAndLayDto
     * @param allWorkFlowName
     * @param listRest
     * @param uploadVersionLogId
     * @param procId
     */
    private void checkRealTaskNodes(VersionZipDto versionZipDto,
                                    RealTimeTaskMenuAndTaskDto workMenuAndLayDto,
                                    VersionWorkflowDto allWorkFlowName,
                                    List<UploadVersionAllJsonCheackLogDto> listRest,
                                    Long uploadVersionLogId,
                                    Integer procId) {
        if (null == workMenuAndLayDto) {
            addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
            return;
        }
        RealTimeTaskVO jobInfoDto = workMenuAndLayDto.getRealTimeTaskVO();
        if (null == jobInfoDto) {
            addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
            return;
        }
        Integer status = 0;
        Map<String, String> restList = new HashMap<>();
        if (jobInfoDto.getTaskType().equals(Constant.RealTimeTaskType.FLINK_SQL.getCode()) || jobInfoDto.getTaskType().equals(Constant.RealTimeTaskType.FLINK_SQL_DAG.getCode())) {
            List<FlinkTaskNodeVO> jobNodeInfos = jobInfoDto.getNodeList();
            if (CollectionUtil.isEmpty(jobNodeInfos)) {
                addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, 0, null, listRest, uploadVersionLogId);
                return;
            }
            for (FlinkTaskNodeVO jobNodeInfo : jobNodeInfos) {
                try {
                    if (Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.source.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kafka.getId())
                            || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kudu.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.hive.getId())) {
                        JSONObject config = jobNodeInfo.getConfig();
                        if (config != null) {
                            //对应的输入输出表是否存在和是否关联到当前这个工程
                            if (StringUtils.isNotEmpty(jobNodeInfo.getTableName())) {
                                String dbName = config.getString("dataBase");
                                if (Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.source.getId()) || Objects.equals(jobNodeInfo.getNodeType(), FlinkNodeType.kafka.getId())) {
                                    BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectOne(new QueryWrapper<BdpRealTableInfo>().eq("db_name", dbName).eq("table_name", jobNodeInfo.getTableName()));
                                    if (null == tableInfo) {
                                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点", "实时表：【" + dbName + "." + jobNodeInfo.getTableName() + "】不存在！" + "验证不通过！");
                                        status++;
                                        continue;
                                    } else {
                                        ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 2));
                                        if (null == procTable) {
                                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点", "实时表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                            status++;
                                            continue;
                                        }
                                    }
                                } else {
                                    TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", dbName).eq("table_name", jobNodeInfo.getTableName()));
                                    if (null == tableInfo) {
                                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点", "输出离线表：【" + dbName + "." + jobNodeInfo.getTableName() + "】不存在！" + "验证不通过！");
                                        status++;
                                        continue;
                                    } else {
                                        ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 1));
                                        if (null == procTable) {
                                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点", "输出离线表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                            status++;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    log.error("{}下的{}节点验证节点异常！error:{}", allWorkFlowName.getName(), jobNodeInfo.getNodeName(), e.getMessage());
                    restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobNodeInfo.getNodeName() + "】节点", "验证异常！" + "验证不通过！");
                    status++;
                }
            }
        }
        if (jobInfoDto.getTaskType().equals(Constant.RealTimeTaskType.REAL_TIME_COLLECTION.getCode())) {
            JSONObject config = jobInfoDto.getConfig();
            if (config != null) {
                String dbName = config.getString("targetDbname");
                String tableName = config.getString("targetTableName");
                Integer connectId = config.getInteger("resourceId");
                //验证连接id
                List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
                if (CollectionUtil.isEmpty(connectList)) {
                    restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "其版本包中接入数据源未关联项目,验证不通过！");
                    status++;
                } else {
                    ConfConnectAndConfigDto confConnectAndConfigDto = null;
                    confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(connectId, o.getId())).findAny().orElse(null);
                    if (null == confConnectAndConfigDto) {
                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "其版本包中接入数据源未关联项目,验证不通过！");
                        status++;
                    } else {
//                    Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
                        //直接改为按照名字进行数据源确认
                        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                                .eq("name", confConnectAndConfigDto.getName()).last(" limit 1 ")
                        );
                        if (null == confConnect) {
                            restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "当前系统数据源【" + confConnectAndConfigDto.getName() + "】不存在,验证不通过！");
                            status++;
                        } else {
                            //数据源连接是否已经关联
                            ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()).last(" limit 1 "));
                            if (null == procConnect) {
                                restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "当前系统数据源【" + confConnect.getName() + "】未关联项目,验证不通过！");
                                status++;
                            } else {
                                //验证输出表是否存在以及是否关联到项目
                                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", dbName).eq("table_name", tableName));
                                if (null == tableInfo) {
                                    restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "输出表：【" + dbName + "." + tableName + "】不存在！" + "验证不通过！");
                                    status++;
                                } else {
                                    ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 2));
                                    if (null == procTable) {
                                        restList.put("【" + allWorkFlowName.getName() + "】下的【" + jobInfoDto.getTaskName() + "】任务", "输出表：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联到项目！" + "验证不通过！");
                                        status++;
                                    }
                                }
                            }
                        }

                    }

                }
            }
        }
        if (status > 0) {
            status = 1;
        }
        addUploadVersionAllJsonCheackLogDto(allWorkFlowName.getName(), allWorkFlowName.getOlderId(), 7, status, JSON.toJSONString(restList), listRest, uploadVersionLogId);
    }

    private void addUploadVersionAllJsonCheackLogDto(String name,
                                                     Long olderId,
                                                     Integer cheackType, Integer status, String
                                                             rest, List<UploadVersionAllJsonCheackLogDto> listRest, Long uploadVersionLogId) {
        UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto = new UploadVersionAllJsonCheackLogDto();
        uploadVersionAllJsonCheackLogDto.setCheackName(name);
        uploadVersionAllJsonCheackLogDto.setCheackStatus(status);
        uploadVersionAllJsonCheackLogDto.setCheackType(cheackType);
        uploadVersionAllJsonCheackLogDto.setOlderCheackDataId(olderId);
        uploadVersionAllJsonCheackLogDto.setUploadVersionLogId(uploadVersionLogId);
        uploadVersionAllJsonCheackLogDto.setRestMsgList(rest);
        listRest.add(uploadVersionAllJsonCheackLogDto);
    }

    private void filterAllWorkFlowNameAndLayName
            (List<WorkMenuAndLayDto> workMenuList, List<VersionWorkflowDto> allWorkFlowName, Boolean
                    isworkflowlay, Boolean isworkflow, List<WorkMenu> newWorkMenus, Boolean reName) {
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = workMenuList.stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
            //按照根菜单进行名字查找看是否存在。当前工程下
            for (Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()) {
                List<WorkMenuAndLayDto> rootWorkMenus = entry.getValue();
                if (CollectionUtil.isNotEmpty(rootWorkMenus)) {
                    Long olderRootId = entry.getKey();
                    List<WorkMenuAndLayDto> olderWorkMenus = entry.getValue();
                    if (null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)) {
                        WorkMenuAndLayDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
                        if (null != workMenuAndLayDto) {
                            StringBuffer sbWorkMenuName = new StringBuffer();
                            List<WorkMenuAndLayDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
                            //根目录的名字
                            sbWorkMenuName.append(workMenuAndLayDto.getName());
                            WorkMenu workMenu = null;
                            if (reName) {
                                if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                                    workMenu = newWorkMenus.stream().filter(o -> (Objects.equals(o.getName(), workMenuAndLayDto.getName()) && Objects.equals(o.getParentId(), 0L))).findAny().orElse(null);
                                }
                            }
                            filterChildrenName(olderChildrens, olderWorkMenus, allWorkFlowName, isworkflowlay, isworkflow, sbWorkMenuName, workMenu, newWorkMenus, reName);
                        }
                    }
                }
            }
        }
    }

    private void filterAllRealWorkFlowName
            (List<RealTimeTaskMenuAndTaskDto> workMenuList, List<VersionWorkflowDto> allWorkFlowName, List<RealTimeTaskMenu> newWorkMenus, Boolean
                    reName) {
        if (CollectionUtil.isNotEmpty(workMenuList)) {
            List<RealTimeTaskMenuAndTaskDto> olderRootWorkMenuLists = workMenuList.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
            //按照根菜单进行名字查找看是否存在。当前工程下
            for (RealTimeTaskMenuAndTaskDto root : olderRootWorkMenuLists) {
                if (root.getMenuType().equals(2)) {
                    Integer isExit = 0;
                    if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                        RealTimeTaskMenu realTimeTaskMenu = newWorkMenus.stream().filter(o -> (Objects.equals(o.getName(), root.getName()) && Objects.equals(o.getParentId(), 0))).findAny().orElse(null);
                        if (realTimeTaskMenu != null) {
                            isExit = 1;
                        }
                    }
                    allWorkFlowName.add(pingVersionVersionWorkflowDto(
                            root.getName(),
                            root.getCreatePerName(), Long.valueOf(root.getId()), 0L, null, isExit, Long.valueOf(root.getId())));
                } else {
                    Integer olderRootId = root.getId();
                    if (null != olderRootId) {
                        StringBuffer sbWorkMenuName = new StringBuffer();
                        List<RealTimeTaskMenuAndTaskDto> olderChildrens = workMenuList.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderRootId)).collect(Collectors.toList());
                        //根目录的名字
                        sbWorkMenuName.append(root.getName());
                        RealTimeTaskMenu workMenu = null;
                        if (reName) {
                            if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                                workMenu = newWorkMenus.stream().filter(o -> (Objects.equals(o.getName(), root.getName()) && Objects.equals(o.getParentId(), 0))).findAny().orElse(null);
                            }
                        }
                        filterRealChildrenName(olderChildrens, workMenuList, allWorkFlowName, sbWorkMenuName, workMenu, newWorkMenus, reName, olderRootId);
                    }
                }
            }
        }
    }

    private void filterChildrenName
            (List<WorkMenuAndLayDto> olderChildrens, List<WorkMenuAndLayDto> olderWorkMenus, List<VersionWorkflowDto> allWorkFlowName, Boolean
                    isworkflowlay, Boolean isworkflow, StringBuffer sbWorkMenuName, WorkMenu
                     workMenu, List<WorkMenu> newWorkMenus, Boolean reName) {
        if (CollectionUtil.isNotEmpty(olderChildrens)) {
            if (CollectionUtil.isNotEmpty(olderChildrens)) {
                for (WorkMenuAndLayDto olderChildren : olderChildrens) {
                    StringBuffer olderTemp = new StringBuffer(sbWorkMenuName);
                    StringBuffer newTemp = olderTemp.append("/").append(olderChildren.getName());
                    WorkMenu childrenWorkMenu = null;
                    if (reName) {
                        if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                            if (null != workMenu) {
                                childrenWorkMenu = newWorkMenus.stream().filter(o -> (Objects.equals(o.getName(), olderChildren.getName()) && Objects.equals(o.getParentId(), workMenu.getId()))).findAny().orElse(null);
                            }
                        }
                    }
                    Integer isExit = 0;
                    Long exitId = 0L;
                    Long exitRootId = 0L;
                    if (null != childrenWorkMenu) {
                        isExit = 1;
                        exitId = childrenWorkMenu.getId();
                        exitRootId = childrenWorkMenu.getRootId();
                    }
                    if (Objects.equals(olderChildren.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())) {
                        if (isworkflow) {
                            allWorkFlowName.add(pingVersionVersionWorkflowDto(
                                    newTemp.toString(),
                                    olderChildren.getCreatePerName(), olderChildren.getId(), exitId, exitRootId, isExit, olderChildren.getRootId()));
                        }
                    } else if (Objects.equals(olderChildren.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())) {
                        if (isworkflowlay) {
                            allWorkFlowName.add(pingVersionVersionWorkflowDto(
                                    newTemp.toString(),
                                    olderChildren.getCreatePerName(), olderChildren.getId(), exitId, exitRootId, isExit, olderChildren.getRootId()));
                        }
                    } else {
                        List<WorkMenuAndLayDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                        filterChildrenName(olderChildrens1, olderWorkMenus, allWorkFlowName, isworkflowlay, isworkflow, newTemp, childrenWorkMenu, newWorkMenus, reName);
                    }
                }
            }
        }
    }

    private void filterRealChildrenName
            (List<RealTimeTaskMenuAndTaskDto> olderChildrens, List<RealTimeTaskMenuAndTaskDto> olderWorkMenus, List<VersionWorkflowDto> allWorkFlowName, StringBuffer
                    sbWorkMenuName, RealTimeTaskMenu
                     workMenu, List<RealTimeTaskMenu> newWorkMenus, Boolean reName, Integer olderRootId) {
        if (CollectionUtil.isNotEmpty(olderChildrens)) {
            if (CollectionUtil.isNotEmpty(olderChildrens)) {
                for (RealTimeTaskMenuAndTaskDto olderChildren : olderChildrens) {
                    StringBuffer olderTemp = new StringBuffer(sbWorkMenuName);
                    StringBuffer newTemp = olderTemp.append("/").append(olderChildren.getName());
                    RealTimeTaskMenu childrenWorkMenu = null;
                    if (reName) {
                        if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                            if (null != workMenu) {
                                childrenWorkMenu = newWorkMenus.stream().filter(o -> (Objects.equals(o.getName(), olderChildren.getName()) && Objects.equals(o.getParentId(), workMenu.getId()))).findAny().orElse(null);
                            }
                        }
                    }
                    Integer isExit = 0;
                    Long exitId = 0L;
                    if (null != childrenWorkMenu) {
                        isExit = 1;
                        exitId = Long.valueOf(childrenWorkMenu.getId());
                    }
                    if (Objects.equals(olderChildren.getMenuType(), 2)) {
                        allWorkFlowName.add(pingVersionVersionWorkflowDto(
                                newTemp.toString(),
                                olderChildren.getCreatePerName(), Long.valueOf(olderChildren.getId()), exitId, null, isExit, Long.valueOf(olderRootId)));
                    } else {
                        List<RealTimeTaskMenuAndTaskDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                        filterRealChildrenName(olderChildrens1, olderWorkMenus, allWorkFlowName, newTemp, childrenWorkMenu, newWorkMenus, reName, olderRootId);
                    }
                }
            }
        }
    }

    private VersionWorkflowDto pingVersionVersionWorkflowDto(String name, String createPerName, Long
            id, Long
                                                                     exitId, Long exitRootId, Integer isExit, Long olderRootId) {
        VersionWorkflowDto versionWorkflowDto = new VersionWorkflowDto();
        versionWorkflowDto.setName(name);
        versionWorkflowDto.setCreateName(createPerName);
        versionWorkflowDto.setOlderId(id);
        versionWorkflowDto.setIsExit(isExit);
        versionWorkflowDto.setExitWorkflowId(exitId);
        versionWorkflowDto.setExitRootId(exitRootId);
        versionWorkflowDto.setOlderRootId(olderRootId);
        return versionWorkflowDto;
    }

    private void checkTables
            (List<TableInfoAndFieldDto> tableList, List<UploadVersionAllJsonCheackLogDto> listRest, Long
                    uploadVersionLogId) {
        if (CollectionUtil.isNotEmpty(tableList)) {
            for (TableInfoAndFieldDto tableInfoAndFieldDto : tableList) {
                UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto = new UploadVersionAllJsonCheackLogDto();
                uploadVersionAllJsonCheackLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionAllJsonCheackLogDto.setCheackName(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName());
                uploadVersionAllJsonCheackLogDto.setOlderCheackDataId(Long.valueOf(tableInfoAndFieldDto.getId()));
                uploadVersionAllJsonCheackLogDto.setCheackStatus(0);
                uploadVersionAllJsonCheackLogDto.setCheackType(2);
                uploadVersionAllJsonCheackLogDto.setRestMsgList("");
                listRest.add(uploadVersionAllJsonCheackLogDto);
            }
        }
    }

    private void checkRealTables
            (List<RealTableInfoAndFieldDto> tableList, List<UploadVersionAllJsonCheackLogDto> listRest, Long
                    uploadVersionLogId) {
        if (CollectionUtil.isNotEmpty(tableList)) {
            for (RealTableInfoAndFieldDto tableInfoAndFieldDto : tableList) {
                UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto = new UploadVersionAllJsonCheackLogDto();
                uploadVersionAllJsonCheackLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionAllJsonCheackLogDto.setCheackName(tableInfoAndFieldDto.getDbName() + "." + tableInfoAndFieldDto.getTableName());
                uploadVersionAllJsonCheackLogDto.setOlderCheackDataId(Long.valueOf(tableInfoAndFieldDto.getId()));
                uploadVersionAllJsonCheackLogDto.setCheackStatus(0);
                uploadVersionAllJsonCheackLogDto.setCheackType(6);
                uploadVersionAllJsonCheackLogDto.setRestMsgList("");
                listRest.add(uploadVersionAllJsonCheackLogDto);
            }
        }
    }

    private void checkConnects
            (List<ConfConnectAndConfigDto> connectList, List<UploadVersionAllJsonCheackLogDto> listRest, Long
                    uploadVersionLogId) {
        if (CollectionUtil.isNotEmpty(connectList)) {
            for (ConfConnectAndConfigDto confConnectAndConfigDto : connectList) {
                UploadVersionAllJsonCheackLogDto uploadVersionAllJsonCheackLogDto = new UploadVersionAllJsonCheackLogDto();
                uploadVersionAllJsonCheackLogDto.setUploadVersionLogId(uploadVersionLogId);
                uploadVersionAllJsonCheackLogDto.setCheackName(confConnectAndConfigDto.getName());
                uploadVersionAllJsonCheackLogDto.setOlderCheackDataId(Long.valueOf(confConnectAndConfigDto.getId()));
                uploadVersionAllJsonCheackLogDto.setCheackStatus(0);
                uploadVersionAllJsonCheackLogDto.setCheackType(1);
                uploadVersionAllJsonCheackLogDto.setRestMsgList("");
                listRest.add(uploadVersionAllJsonCheackLogDto);
            }
        }
    }

    private List<TableFieldInfo> deleteTables(Integer procId, TableInfo tableInfo, boolean falge, Integer
            importChangeRole) {

        //删除数据仓库中的表
        String jdbcUrl = hiveConfig.getHiveserverurl();
        if (StorageEngineEnum.KUDU.getCode().equals(tableInfo.getStoreEngine())) {
            jdbcUrl = hiveConfig.getKuduJdbcUrl();
        }
        HiveTableUtil hiveTableUtil = new HiveTableUtil(jdbcUrl, tableInfo.getDbName(), "hdfs", "hdfs");
        List<TableFieldInfo> tableFieldInfos = tableFieldInfoMapper.selectList(new QueryWrapper<TableFieldInfo>().eq("table_id", tableInfo.getId()));
        //删除表的代码修改
        List<TableRegisterEntity> registerEntityList = new ArrayList<>();
        long startTime = new Date().getTime();
        if (tableInfoService.deleteDbTable(tableInfo, registerEntityList, falge)) {
            try {
                hiveTableUtil.dropTable(tableInfo.getTableName());
                hiveTableUtil.close();
                if (falge) {
                    tableInfoService.addRegisterDelete(startTime, registerEntityList, importChangeRole);
                    //删除关联关系
                    procTableMapper.delete(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("tableType", 1));
                }
            } catch (Exception e) {
                log.error("删除数据仓库：【{}.{}】异常:error:{}", tableInfo.getDbName(), tableInfo.getTableName(), e.getMessage());
                hiveTableUtil.close();
                throw new RRException("删除数据仓库：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】异常error:{}" + e.getMessage());
            }
        }
        return tableFieldInfos;
    }

    private List<BdpRealTableField> deleteRealTables(Integer procId, BdpRealTableInfo tableInfo, boolean falge, Integer
            importChangeRole) {

        //删除数据仓库中的表
        List<BdpRealTableField> tableFieldInfos = realTableFieldMapper.selectList(new QueryWrapper<BdpRealTableField>().eq("table_id", tableInfo.getId()));
        //删除表的代码修改
        List<TableRegisterEntity> registerEntityList = new ArrayList<>();
        long startTime = new Date().getTime();
        realTableInfoService.removeById(tableInfo.getId());
        if (falge) {
            TableRegisterEntity registerEntity = new TableRegisterEntity();
            Date curr = new Date();
            registerEntity.setTableInfoId(tableInfo.getId());
            registerEntity.setBatchNum(curr.getTime());
            long cost = curr.getTime() - startTime;
            registerEntity.setCost(cost);
            registerEntity.setRunTime(curr);
            registerEntity.setRunUser(ShiroUtils.getUserId());
            tableRegisterService.save(registerEntity);
            //删除关联关系
            procTableMapper.delete(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("tableType", 2));
        }
        return tableFieldInfos;
    }

    //kudu表的编辑有点复杂
    private Integer insertOrUpdateTable(TableInfoAndFieldDto tableInfoAndFieldDto, Integer procId, Integer
            tableId, List<TableFieldInfo> olderTbaleFields, Long rowsNum, Double totalSize, Date
                                                nowDates, Integer
                                                importChangeRole, Integer tenantId, TableInfo olderTableInfo) {

        TableInfo tableInfo = new TableInfo();
        BeanUtils.copyProperties(tableInfoAndFieldDto, tableInfo);
        tableInfo.setRowsNum(rowsNum);
        tableInfo.setTotalSize(totalSize);
        tableInfo.setUpdateTime(nowDates);
        tableInfo.setTenantId(tenantId);
        List<TableFieldInfo> tableFieldInfos = tableInfoAndFieldDto.getTableFieldInfos();
        if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
            tableInfo.setTableFieldInfos(tableFieldInfos);
        }
        //创建hive仓库表数据或者是新建kudu表
        long startTime = new Date().getTime();
        if (null == tableInfo.getStoreEngine()) {
            //如果没有，则默认为hive引擎
            tableInfo.setStoreEngine(1);
        }
        //用户id得替换
        Integer userId = sysUserService.getUserId(tableInfoAndFieldDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
        if (StorageEngineEnum.HIVE.getCode().equals(tableInfo.getStoreEngine())
                || null == tableId) {
            try {
                if (null != olderTableInfo) {
                    //修改
                    tableInfo.setCreatePer(olderTableInfo.getCreatePer());
                    tableInfo.setCreateTime(olderTableInfo.getCreateTime());
                    tableInfo.setUpdatePer(olderTableInfo.getUpdatePer());
                    tableInfo.setUpdateTime(olderTableInfo.getUpdateTime());
                    tableInfo.setLastCountTime(olderTableInfo.getLastCountTime());
                } else {
                    tableInfo.setCreatePer(userId);
                }
                R hiveTableMap = HiveTableDdl.createHiveTable(tableInfo, hiveConfig);
                if (null != hiveTableMap && hiveTableMap.get("code").equals(0)) {
                    Integer registerType = null == tableId ? TableRegisterTypeEnum.OFFLINE_ADD.getCode() : TableRegisterTypeEnum.OFFLINE_UPDATE.getCode();
                    //才生成对应的数据
                    gengLockTable(tableId, tableInfo, tableFieldInfos, olderTbaleFields, userId);

                    //注册数据表数据
                    Date curr = new Date();
                    TableRegisterEntity registerEntity = new TableRegisterEntity();
                    registerEntity.setTableInfoId(tableInfo.getId());
                    registerEntity.setBatchNum(curr.getTime());
                    registerEntity.setRegisterType(registerType);
                    long cost = curr.getTime() - startTime;
                    registerEntity.setCost(cost);
                    registerEntity.setRunTime(curr);
                    registerEntity.setRunUser(tableInfo.getCreatePer().longValue());
                    Long roleId = null == importChangeRole ? 1L : Long.valueOf(importChangeRole);
                    registerEntity.setRoleId(roleId);
                    tableRegisterService.save(registerEntity);

                    //刷新对应的数据
                    //修改表数据后刷新表结构重新识别旧的数据
                    if (null != tableId) {
                        if (Objects.equals(StorageEngineEnum.HIVE.getCode(), tableInfo.getStoreEngine())) {
                            HiveTableUtil hiveTableUtil = new HiveTableUtil(hiveConfig.getHiveserverurl(), tableInfo.getDbName(), "hdfs", "hdfs");
                            try {
                                hiveTableUtil.repairTable(tableInfo.getTableName());
                                hiveTableUtil.close();
                            } catch (Exception e) {
                                log.error("repair数据仓库：【{}.{}】异常", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
                                hiveTableUtil.close();
                            }
                        }
                    }

                    //先查询是否关联了，如果没有关联，则删除重新建，如果有则不做修改
                    List<ProcTable> procTables = procTableMapper.selectList(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 1));
                    if (CollectionUtil.isNotEmpty(procTables)) {
                        procTableMapper.deleteBatchIds(procTables.stream().map(ProcTable::getId).collect(Collectors.toList()));
                    }
                    ProcTable procTable = new ProcTable();
                    procTable.setTableId(tableInfo.getId());
                    procTable.setProcId(procId);
                    procTableMapper.insert(procTable);
                } else {
                    Object msg = null;
                    if (null != hiveTableMap) {
                        msg = hiveTableMap.get("msg");
                    }
                    log.error("生成数据仓库：【{}.{}】异常", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
                    //创建之前的表
                    try {
                        tableInfo.setTableFieldInfos(olderTbaleFields);
                        HiveTableDdl.createHiveTable(tableInfo, hiveConfig);
                    } catch (Exception e) {
                        log.error("回滚到之前的 表异常！");
                    }
                    throw new RRException("" + msg);
                }
            } catch (Exception e) {
                log.error("生成数据仓库：【{}.{}】异常", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
                throw new RRException(e.getMessage());
            }
        }
        //编辑kudu表结构和数据
        if (StorageEngineEnum.KUDU.getCode().equals(tableInfo.getStoreEngine())
                && null != tableId) {
            tableInfo.setId(tableId);
            //判断表结构是否有修改
            Boolean isNeedChange = null;
            try {
                isNeedChange = updateKuduTable(tableFieldInfos, olderTbaleFields, tableInfo, tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName(), false, procId, importChangeRole);
            } catch (Exception e) {
                log.error("修改kudu数据仓库：【{}.{}】异常", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
                throw new RRException(e.getMessage());
            }
            //修改本地数据库
            gengLockTable(tableId, tableInfo, tableFieldInfos, olderTbaleFields, userId);

            if (null != importChangeRole || isNeedChange) {
                //编辑表注册记录到元数据关联注册表中
                //注册数据表数据
                Date curr = new Date();
                TableRegisterEntity registerEntity = new TableRegisterEntity();
                registerEntity.setTableInfoId(tableInfo.getId());
                registerEntity.setBatchNum(curr.getTime());
                registerEntity.setRegisterType(TableRegisterTypeEnum.OFFLINE_UPDATE.getCode());
                long cost = curr.getTime() - startTime;
                registerEntity.setCost(cost);
                registerEntity.setRunTime(curr);
                registerEntity.setRunUser(tableInfo.getCreatePer().longValue());
                Long roleId = null == importChangeRole ? 1L : Long.valueOf(importChangeRole);
                registerEntity.setRoleId(roleId);
                tableRegisterService.save(registerEntity);
            }
        }

        return tableInfo.getId();

    }

    private Integer insertOrUpdateRealTable(RealTableInfoAndFieldDto tableInfoAndFieldDto, Integer
            procId, Integer
                                                    tableId, List<BdpRealTableField> olderTbaleFields, Date nowDates, Integer
                                                    importChangeRole, Integer tenantId, BdpRealTableInfo olderTableInfo) {

        BdpRealTableInfo tableInfo = new BdpRealTableInfo();
        BeanUtils.copyProperties(tableInfoAndFieldDto, tableInfo);
        tableInfo.setUpdateTime(nowDates);
        tableInfo.setTenantId(tenantId);
        List<BdpRealTableField> tableFieldInfos = tableInfoAndFieldDto.getTableFieldInfos();
        long startTime = new Date().getTime();
        //用户id得替换
        Integer userId = sysUserService.getUserId(tableInfoAndFieldDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
        if (null != olderTableInfo) {
            //修改
            tableInfo.setCreateUser(olderTableInfo.getCreateUser());
            tableInfo.setCreateTime(olderTableInfo.getCreateTime());
            tableInfo.setUpdateUser(olderTableInfo.getUpdateUser());
            tableInfo.setUpdateTime(olderTableInfo.getUpdateTime());
        } else {
            tableInfo.setCreateUser(Long.valueOf(userId));
        }
        try {
            Integer registerType = null == tableId ? TableRegisterTypeEnum.ONLINE_ADD.getCode() : TableRegisterTypeEnum.ONLINE_UPDATE.getCode();
            //才生成对应的数据
            gengLockRealTable(tableId, tableInfo, tableFieldInfos, olderTbaleFields, userId);

            //注册数据表数据
            Date curr = new Date();
            TableRegisterEntity registerEntity = new TableRegisterEntity();
            registerEntity.setTableInfoId(tableInfo.getId());
            registerEntity.setBatchNum(curr.getTime());
            registerEntity.setRegisterType(registerType);
            long cost = curr.getTime() - startTime;
            registerEntity.setCost(cost);
            registerEntity.setRunTime(curr);
            registerEntity.setRunUser(tableInfo.getCreateUser().longValue());
            Long roleId = null == importChangeRole ? 1L : Long.valueOf(importChangeRole);
            registerEntity.setRoleId(roleId);
            tableRegisterService.save(registerEntity);

            new Thread(() -> {
                if (RealTableType.INNER.getCode().equals(tableInfo.getTableType())) {
                    LocalKafkaUtil.createTopic(tableInfo.getTopicName(),
                            tableInfo.getPartitionNum(), tableInfo.getDuplicateNum(), kafkaUrl);
                }
            }).start();

            //先查询是否关联了，如果没有关联，则删除重新建，如果有则不做修改
            List<ProcTable> procTables = procTableMapper.selectList(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).eq("table_type", 2));
            if (CollectionUtil.isNotEmpty(procTables)) {
                procTableMapper.deleteBatchIds(procTables.stream().map(ProcTable::getId).collect(Collectors.toList()));
            }
            ProcTable procTable = new ProcTable();
            procTable.setTableId(tableInfo.getId());
            procTable.setProcId(procId);
            procTable.setTableType(2);
            procTableMapper.insert(procTable);
        } catch (Exception e) {
            log.error("生成实时表：【{}.{}】异常", tableInfoAndFieldDto.getDbName(), tableInfoAndFieldDto.getTableName());
            try {
                bdpRealTableInfoMapper.insertAndId(olderTableInfo);
                realTableFieldMapper.batchInsertAndId(olderTbaleFields);
            } catch (Exception e1) {
                log.error("回滚到之前的 实时表异常！");
            }

            throw new RRException(e.getMessage());
        }
        return tableInfo.getId();

    }

    private void gengLockTable(Integer tableId, TableInfo
            tableInfo, List<TableFieldInfo> tableFieldInfos, List<TableFieldInfo> olderTbaleFields, Integer
                                       userId) {
        if (null != tableId) {
            tableInfo.setId(tableId);
            tableInfo.setCreatePer(userId);
            if (StorageEngineEnum.KUDU.getCode().equals(tableInfo.getStoreEngine())) {
                //删除，在新增
                tableInfoMapper.deleteById(tableId);
                tableFieldInfoMapper.delete(new QueryWrapper<TableFieldInfo>().eq("table_id", tableId));
            }
            tableInfoMapper.insertAndId(tableInfo);
        } else {
            tableInfoMapper.insert(tableInfo);
        }
        //生成对应的字段
        Set<String> dtata = new HashSet<>();
        Map<String, List<TableFieldInfo>> dataList = null;
        if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
            List<TableFieldInfo> lists = new ArrayList<>();
            List<TableFieldInfo> listsNoIds = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(olderTbaleFields)) {
                dataList = olderTbaleFields.stream().collect(Collectors.groupingBy(TableFieldInfo::getFieldName));
                dtata.addAll(dataList.keySet());
            }
            for (TableFieldInfo tableFieldInfo : tableFieldInfos) {
                tableFieldInfo.setTableId(tableInfo.getId());
                tableFieldInfo.setCreatePer(userId);
                if (dtata.contains(tableFieldInfo.getFieldName())) {
                    tableFieldInfo.setId(dataList.get(tableFieldInfo.getFieldName()).get(0).getId());
                    lists.add(tableFieldInfo);
                } else {
                    listsNoIds.add(tableFieldInfo);
                }
            }
            //批量生成字段数据
            if (CollectionUtil.isNotEmpty(lists)) {
                tableFieldInfoMapper.batchInserts(lists);
            }
            if (CollectionUtil.isNotEmpty(listsNoIds)) {
                tableFieldInfoService.saveBatch(listsNoIds);
            }
        }
    }

    private void gengLockRealTable(Integer tableId, BdpRealTableInfo
            tableInfo, List<BdpRealTableField> tableFieldInfos, List<BdpRealTableField> olderTbaleFields, Integer
                                           userId) {
        if (null != tableId) {
            tableInfo.setId(tableId);
            tableInfo.setCreateUser(Long.valueOf(userId));
            //删除，在新增
            bdpRealTableInfoMapper.deleteById(tableId);
            realTableFieldMapper.delete(new QueryWrapper<BdpRealTableField>().eq("table_id", tableId));
            bdpRealTableInfoMapper.insertAndId(tableInfo);
        } else {
            bdpRealTableInfoMapper.insert(tableInfo);
        }
        //生成对应的字段
        Set<String> dtata = new HashSet<>();
        Map<String, List<BdpRealTableField>> dataList = null;
        if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
            List<BdpRealTableField> lists = new ArrayList<>();
            List<BdpRealTableField> listsNoIds = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(olderTbaleFields)) {
                dataList = olderTbaleFields.stream().collect(Collectors.groupingBy(BdpRealTableField::getFieldName));
                dtata.addAll(dataList.keySet());
            }
            for (BdpRealTableField tableFieldInfo : tableFieldInfos) {
                tableFieldInfo.setTableId(tableInfo.getId());
                tableFieldInfo.setCreateUser(Long.valueOf(userId));
                if (dtata.contains(tableFieldInfo.getFieldName())) {
                    tableFieldInfo.setId(dataList.get(tableFieldInfo.getFieldName()).get(0).getId());
                    lists.add(tableFieldInfo);
                } else {
                    listsNoIds.add(tableFieldInfo);
                }
            }
            //批量生成字段数据
            if (CollectionUtil.isNotEmpty(lists)) {
                realTableFieldMapper.batchInsertAndId(lists);
            }
            if (CollectionUtil.isNotEmpty(listsNoIds)) {
                realTableFieldMapper.batchInsert(listsNoIds);
            }
        }
    }

    @Override
    public Boolean updateKuduTable
            (List<TableFieldInfo> tableFieldInfos, List<TableFieldInfo> olderTbaleFields, TableInfo tableInfo,
             String dbName, String tableName, Boolean containtsId, Integer procId, Integer importChangeRole) {
        List<TableFieldInfo> updateTableFields = new ArrayList<>();
        List<TableFieldInfo> dropTableFields = new ArrayList<>();
        List<TableFieldInfo> addTableFields = new ArrayList<>();
        List<TableFieldInfo> updateTablePros = new ArrayList<>();
        Boolean isNeedChange = false;
        Boolean isDeleteAndAdd = true;
        //先判断主键是有有修改，如果有修改，则新删除后新增
        if (CollectionUtil.isNotEmpty(olderTbaleFields)) {
            List<TableFieldInfo> tableFieldInfosoo1 = olderTbaleFields.stream().filter(o -> Objects.equals(o.getPrimaryKey(), 1)).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(tableFieldInfosoo1)) {
                if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    List<TableFieldInfo> collect = tableFieldInfos.stream().filter(o -> Objects.equals(o.getPrimaryKey(), 1)).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(collect)) {
                        TableFieldInfo tableFieldInfo = collect.get(0);
                        TableFieldInfo tableFieldInfo1 = tableFieldInfosoo1.get(0);
                        //主键一样，则修改字段和对应的属性
                        if (Objects.equals(tableFieldInfo.getFieldName(), tableFieldInfo1.getFieldName()) && Objects.equals(tableFieldInfo.getFieldType(), tableFieldInfo1.getFieldType())) {
                            isDeleteAndAdd = false;
                        }
                    }
                }
                //先删除，再新增
                if (isDeleteAndAdd) {
                    if (null != procId) {
                        deleteTables(procId, tableInfo, false, importChangeRole);
                        R hiveTableMap = HiveTableDdl.createHiveTable(tableInfo, hiveConfig);
                        //创建失败，则还原之前的，并且报错
                        if (!(null != hiveTableMap && hiveTableMap.get("code").equals(0))) {
                            //创建之前的表
                            try {
                                tableInfo.setTableFieldInfos(olderTbaleFields);
                                HiveTableDdl.createHiveTable(tableInfo, hiveConfig);
                            } catch (Exception e) {
                                log.error("回滚到之前的 表异常！");
                            }
                            if (null != hiveTableMap) {
                                throw new RRException("" + hiveTableMap.get("msg"));
                            }
                        }
                    }
                    return true;
                }
            }
        }
        //修改是否含有id--是的是离线数据仓库的修改
        if (containtsId) {
            isNeedChange = tableInfoService.initKuduChangeSql(updateTableFields, dropTableFields, addTableFields, updateTablePros, tableFieldInfos, olderTbaleFields);
        } else {
            isNeedChange = tableInfoService.initKuduChange(updateTableFields, dropTableFields, addTableFields, updateTablePros, tableFieldInfos, olderTbaleFields);
        }
        if (isNeedChange) {
            //修改表结构
            List<TableInfoAndFieldDto> needUpdates = tableInfoService.initKuduSql(updateTableFields, dropTableFields, addTableFields, updateTablePros, tableInfo);
            if (CollectionUtil.isNotEmpty(needUpdates)) {
                Boolean isSuccess = HiveTableDdl.updateKuduTable(needUpdates, tableInfo, hiveConfig);
                if (!isSuccess) {
                    //回滚
                    List<TableSqlDto> needRockSqls = new ArrayList<>();
                    String errMsg = "";
                    Integer isError = null;
                    for (TableInfoAndFieldDto needUpdate : needUpdates) {
                        List<TableSqlDto> tableSqlDtos = needUpdate.getTableSqlDtos();
                        isError = 0;
                        if (CollectionUtil.isNotEmpty(tableSqlDtos)) {
                            //修改属性（新增一个字段 xxxx_copy_tmp_gctcl  将数据赋值给这个字段  删除之前的字段  修改字段名字 xxxx）
                            if (tableSqlDtos.size() > 1) {
                                List<TableSqlDto> tmpTableSqlDtos = new ArrayList<>();
                                for (TableSqlDto tableSqlDto : tableSqlDtos) {
                                    if (Objects.equals(1, isError)) {
//                                        if(CollectionUtil.isNotEmpty(tmpTableSqlDtos)){
//                                            //到第几步了，回滚的操作也不一样
//                                            TableSqlDto tableSqlDto1 = tableSqlDtos.stream().filter(o -> Objects.equals(o.getIsSuccess(), 1)).findAny().orElse(null);
//                                            List<TableSqlDto> ttmps = tableInfoService.rockSteps(tmpTableSqlDtos,tableSqlDto1.getIsSteps());
//                                            if(CollectionUtil.isNotEmpty(ttmps)){
//                                                needRockSqls.addAll(ttmps);
//                                            }
//                                        }
                                        break;
                                    }
                                    if (Objects.equals(tableSqlDto.getIsExces(), 1)) {
                                        if (!Objects.equals(tableSqlDto.getIsSuccess(), 1)) {
                                            tmpTableSqlDtos.add(tableSqlDto);
                                        } else {
                                            isError = 1;
                                            errMsg = tableSqlDto.getMsg();
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                if (Objects.equals(1, isError)) {
                                    if (CollectionUtil.isNotEmpty(tmpTableSqlDtos)) {
                                        //到第几步了，回滚的操作也不一样
                                        TableSqlDto tableSqlDto1 = tableSqlDtos.stream().filter(o -> Objects.equals(o.getIsSuccess(), 1)).findAny().orElse(null);
                                        List<TableSqlDto> ttmps = tableInfoService.rockSteps(tmpTableSqlDtos, tableSqlDto1.getIsSteps());
                                        if (CollectionUtil.isNotEmpty(ttmps)) {
                                            needRockSqls.addAll(ttmps);
                                        }
                                    }
                                    break;
                                } else {
                                    //都成功了，全部回滚
                                    List<TableSqlDto> ttmps = tableInfoService.rockSteps(tmpTableSqlDtos, 4);
                                    if (CollectionUtil.isNotEmpty(ttmps)) {
                                        needRockSqls.addAll(ttmps);
                                    }
                                }
                            } else {
                                TableSqlDto tableSqlDto = tableSqlDtos.get(0);
                                if (Objects.equals(tableSqlDto.getIsExces(), 1)) {
                                    if (Objects.equals(tableSqlDto.getIsSuccess(), 1)) {
                                        //失败
                                        errMsg = tableSqlDto.getMsg();
                                        isError = 1;
                                        break;
                                    } else {
                                        //得到对应的反向执行的sql
                                        String sql = tableInfoService.rockKuduSql(tableSqlDto);
                                        if (StringUtils.isNotEmpty(sql)) {
                                            TableSqlDto newTableSqlDto = new TableSqlDto();
                                            BeanUtils.copyProperties(tableSqlDto, newTableSqlDto);
                                            newTableSqlDto.setSql(sql);
                                            needRockSqls.add(newTableSqlDto);
                                        }
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    //逆向回滚
                    if (CollectionUtil.isNotEmpty(needRockSqls)) {
                        Collections.reverse(needRockSqls);
                        HiveTableDdl.rockKuduSqls(needRockSqls, tableInfo, hiveConfig);
                    }
                    //抛出异常
                    if (StringUtils.isNotEmpty(errMsg)) {
                        log.error("修改kudu数据仓库：【{}.{}】异常", dbName, tableName);
                        throw new RRException("" + errMsg);
                    }
                }
            }
        }
        return isNeedChange;
    }


    private void deleteConnects(Integer procId, Integer id) {

        procConnectMapper.delete(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", id));
        confConnectMapper.deleteById(id);
        connectFieldInfoMapper.delete(new QueryWrapper<ConnectFieldInfo>().eq("connect_id", id));
        sapConnectFieldMapper.delete(new QueryWrapper<SapConnectField>().eq("connect_id", id));

    }

    private Integer insertOrUpdate(ConfConnectAndConfigDto confConnectAndConfigDto, Integer procId, Integer
            connectId, Integer userId, Integer tenantId) {

        ConfConnect confConnect = new ConfConnect();
        BeanUtils.copyProperties(confConnectAndConfigDto, confConnect);
        confConnect.setCreatePer(userId);
        confConnect.setTenantId(tenantId);
        //启用状态
        confConnect.setConnectEnable(1);
        if (null != connectId) {
            confConnect.setId(connectId);
            confConnectMapper.insertAndId(confConnect);
        } else {
            confConnectMapper.insert(confConnect);
        }
        List<ConnectFieldInfo> connectFieldInfos = confConnectAndConfigDto.getConnectFieldInfos();
        if (CollectionUtil.isNotEmpty(connectFieldInfos)) {
            for (ConnectFieldInfo connectFieldInfo : connectFieldInfos) {
                connectFieldInfo.setConnectId(confConnect.getId());
            }
            connectFieldInfoService.saveBatch(connectFieldInfos);
        }
        SapConnectField sapConnectFieldInfo = confConnectAndConfigDto.getSapConnectFieldInfo();
        if (null != sapConnectFieldInfo) {
            sapConnectFieldInfo.setConnectId(confConnect.getId());
            if (CollectionUtil.isNotEmpty(sapConnectFieldInfo.getAinputParams())) {
                sapConnectFieldInfo.setInputParams(JSON.toJSONString(sapConnectFieldInfo.getAinputParams()));
            }
            if (CollectionUtil.isNotEmpty(sapConnectFieldInfo.getAoutputParams())) {
                sapConnectFieldInfo.setOutputParams(JSON.toJSONString(sapConnectFieldInfo.getAoutputParams()));
            }
            sapConnectFieldMapper.insert(sapConnectFieldInfo);
        }

        //先查询是否关联了，如果没有关联，则删除重新建，如果有则不做修改
        List<ProcConnect> procConnects = procConnectMapper.selectList(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()));
        if (CollectionUtil.isNotEmpty(procConnects)) {
            procConnectMapper.deleteBatchIds(procConnects.stream().map(ProcConnect::getId).collect(Collectors.toList()));
        }

        ProcConnect procConnect = new ProcConnect();
        procConnect.setProcId(procId);
        procConnect.setConnectId(confConnect.getId());
        procConnectMapper.insert(procConnect);

        return confConnect.getId();

    }

    private void genWorkFlowAndJobNodeAndConfig(WorkMenuAndLayDto
                                                        parentWorkMenuAndLayDto, WorkMenuAndLayDto
                                                        otherWorkFlow,
                                                Integer procId, Long newRootId, VersionZipDto versionZipDto, JobInfoDto jobInfoDto,
                                                List<JobNodeInfo> olderJobNodeInfos, Long workMenuNewId, Integer jobId, Long
                                                        workMenuLayId, Long
                                                        logId, Integer tenantId) throws Exception {
        //导入状态  0：成功  1：失败  2：待导入  3：导入中
        final Integer[] importStatus = {0};
        StringBuilder stringBuilder = new StringBuilder();
        WorkMenu workMenu = addDefaultWorkFlowMenu(otherWorkFlow, procId, parentWorkMenuAndLayDto.getNewId(), newRootId, workMenuNewId, jobId);
        otherWorkFlow.setNewId(workMenu.getId());
        uploadVersionWorkflowResultLogMapper.updateWorkMenuId(workMenu.getId(), logId);

        //关联表
        WorkMenuJobRel workMenuJobRel = workMenuJobRelMapper.selectOne(new QueryWrapper<WorkMenuJobRel>().eq("proc_id", procId).eq("work_menu_id", workMenu.getId()).eq("work_type", 1));
        //jobInfo表
        JobInfo jobInfo = jobInfoMapper.selectById(workMenuJobRel.getWorkFlowId());
        if (null != jobInfoDto) {
            jobInfoDto.setNewId(jobInfo.getId());
        }

        //重置新的id
        otherWorkFlow.setNewRootId(workMenu.getRootId());
        otherWorkFlow.setNewProcId(Long.valueOf(procId));
        otherWorkFlow.setNewParentId(parentWorkMenuAndLayDto.getNewId());
        otherWorkFlow.setNewId(workMenu.getId());

        //新增空的jobNode
        List<JobNodeInfoDto> nodes = new ArrayList<>();
        List<JobNodeInfo> newJobNodeInfos = new ArrayList<>();
        List<JobNodeInfo> needJobNodeInfos = new ArrayList<>();
        if (null != jobInfoDto && CollectionUtil.isNotEmpty(jobInfoDto.getJobNodeInfos())) {
            List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
            jobNodeInfos.forEach(o -> {
                if (Objects.equals(o.getTypeId(), JobType.INPUT.getCode())
                        || Objects.equals(o.getTypeId(), JobType.SQL.getCode())
                        || Objects.equals(o.getTypeId(), JobType.OUTPUT.getCode())
                        || Objects.equals(o.getTypeId(), JobType.SHELL.getCode())) {
                    needJobNodeInfos.add(o);
                }
            });
            if (CollectionUtil.isEmpty(needJobNodeInfos)) {
                return;
            }
            final CountDownLatch latch = new CountDownLatch(needJobNodeInfos.size());
            long startTimes = System.currentTimeMillis();
            System.out.println("开始导入数据：" + needJobNodeInfos.size() + ",时间：" + startTimes);
            for (JobNodeInfo jobNodeInfo : needJobNodeInfos) {
                //先按照顺序添加节点（保证顺序一致）
                JobNodeInfoDto jobNodeInfoDto = new JobNodeInfoDto();
                if (!Objects.equals(JobType.INPUT.getCode(), jobNodeInfo.getTypeId())
                        && !Objects.equals(JobType.SQL.getCode(), jobNodeInfo.getTypeId())
                        && !Objects.equals(JobType.OUTPUT.getCode(), jobNodeInfo.getTypeId())
                        && !Objects.equals(JobType.SHELL.getCode(), jobNodeInfo.getTypeId())) {
                    return;
                }
                if (null != jobNodeInfo.getPosY() && null != jobNodeInfo.getPosX()) {
                    BeanUtils.copyProperties(jobNodeInfo, jobNodeInfoDto);
                    nodes.add(jobNodeInfoDto);
                }
                JobNodeInfo newJobNodeInfo = addJobNodeInfo(jobNodeInfo, jobInfo.getId(), procId);
                //更新新的id和新的jobId
                jobNodeInfo.setNewId(newJobNodeInfo.getId());
                jobNodeInfo.setNewJobId(jobInfo.getId());
                if (null != newJobNodeInfo.getPosY() && null != newJobNodeInfo.getPosX()) {
                    jobNodeInfoDto.setCreatePer(newJobNodeInfo.getCreatePer());
                    jobNodeInfoDto.setId(newJobNodeInfo.getId());
                    jobNodeInfoDto.setJobId(jobInfo.getId());
                }
                //生成关联关系
                addWorkMenuJobRel(newJobNodeInfo.getId(), workMenu.getId(), procId);

                ExecutorService es1 = Executors.newSingleThreadExecutor();
                es1.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            //生成节点的配置信息
                            JobNodeConfig jobNodeConfig = jobNodeInfo.getJobNodeConfig();
                            if (null != jobNodeConfig) {
                                //节点中所有的数据源id和表id都需要改
                                jobNodeConfig.setJobNodeId(newJobNodeInfo.getId());
                                if (Objects.equals(newJobNodeInfo.getTypeId(), JobType.INPUT.getCode())) {
                                    //连接id
                                    List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
                                    if (CollectionUtil.isEmpty(connectList)) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + jobNodeConfig.getInput_connect_id() + "】不存在！");
                                    }
                                    ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getInput_connect_id(), o.getId())).findAny().orElse(null);
                                    if (null == confConnectAndConfigDto) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + jobNodeConfig.getInput_connect_id() + "】不存在！");
                                    }
//                                    Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
                                    ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                                                    .eq("name", confConnectAndConfigDto.getName())
                                                    .eq("tenant_id", tenantId).last(" limit 1 ")
//                                            .eq("create_per",userId)
                                    );
                                    if (null == confConnect) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + confConnectAndConfigDto.getName() + "】不存在！");
                                    } else {
                                        //数据源连接是否已经关联
                                        ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>()
                                                .eq("proc_id", procId).eq("connect_id", confConnect.getId()).last(" limit 1 "));
                                        if (null == procConnect) {
                                            throw new RRException("【" + jobNodeInfo.getName() + "】节点,当前系统数据源【" + confConnect.getName() + "】未关联项目！");
                                        }
                                    }
                                    jobNodeConfig.setInput_connect_id(confConnect.getId());
                                    //如果有参数还得添加上对应的参数

                                    //验证表
                                    if (StringUtils.isNotEmpty(jobNodeConfig.getOutput_db_name()) && StringUtils.isNotEmpty(jobNodeConfig.getOutput_table_name())) {
                                        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>()
                                                .eq("db_name", jobNodeConfig.getOutput_db_name()).eq("table_name", jobNodeConfig.getOutput_table_name()));
                                        if (null == tableInfo) {
                                            throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据仓库：【" + jobNodeConfig.getOutput_db_name() + "." + jobNodeConfig.getOutput_table_name() + "】不存在！");
                                        } else {
                                            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()).last(" limit 1 "));
                                            if (null == procTable) {
                                                throw new RRException("节点：【" + jobNodeInfo.getName() + "】下的数据仓库：【" + jobNodeConfig.getOutput_db_name() + "." + jobNodeConfig.getOutput_table_name() + "】未关联项目！");
                                            }
                                        }
                                    }

                                    if (Objects.equals(confConnect.getTypeId(), ConnectTypeEnum.Sap.getCode())) {
                                        //bdp_sap_connect_field 需要改变id
                                        SapConnectField sapConnectFieldInfo = jobNodeConfig.getSapConnectFieldInfo();
                                        SapConnectField sapConnectField = sapConnectFieldMapper.selectOne(new QueryWrapper<SapConnectField>().eq("connect_id", confConnect.getId()));
                                        if (null == sapConnectField) {
                                            throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的sap连接：【" + confConnect.getName() + "】的输入参数存在异常，请检查！");
                                        }
                                        sapConnectFieldInfo.setId(sapConnectField.getId());
                                        sapConnectFieldInfo.setConnectId(confConnect.getId());

                                        //仓库表
                                        List<String> sap_output_table_name = jobNodeConfig.getSap_output_table_name();
                                        if (CollectionUtil.isNotEmpty(sap_output_table_name)) {
                                            for (String s : sap_output_table_name) {
                                                if (!Objects.equals("[]", s) && StringUtils.isNotEmpty(s)) {
                                                    String[] split = s.split("\\.");
                                                    if (split.length > 1) {
                                                        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
                                                        if (null == tableInfo) {
                                                            throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据仓库：【" + s + "】不存在！");
                                                        } else {
                                                            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
                                                            if (null == procTable) {
                                                                throw new RRException("节点：【" + jobNodeInfo.getName() + "】下的数据仓库：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联项目！");
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (Objects.equals(newJobNodeInfo.getTypeId(), JobType.SQL.getCode())) {
                                    //输出表设置
                                    List<String> jobOutPutTableNames = jobNodeConfig.getJobOutPutTableNames();
                                    if (CollectionUtil.isNotEmpty(jobOutPutTableNames)) {
                                        List<String> newJobOutPutTableIds = new ArrayList<>();
                                        for (int i = 0; i < jobOutPutTableNames.size(); i++) {
                                            String s = jobOutPutTableNames.get(i);
                                            if (StringUtils.isNotEmpty(s)) {
                                                String[] split = s.split("\\.");
                                                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
                                                if (null == tableInfo) {
                                                    throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据仓库：【" + split[0].trim() + "." + split[1].trim() + "】不存在！");
                                                } else {
                                                    ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
                                                    if (null == procTable) {
                                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】下的数据仓库：【" + tableInfo.getDbName() + "." + tableInfo.getTableName() + "】未关联项目！");
                                                    }
                                                }
                                                newJobOutPutTableIds.add(tableInfo.getId().toString());
                                            }
                                        }
                                        jobNodeConfig.setJobOutPutTableIds(newJobOutPutTableIds);
                                    }

                                }
                                if (Objects.equals(newJobNodeInfo.getTypeId(), JobType.OUTPUT.getCode())) {
                                    //输出的连接id
                                    List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
                                    if (CollectionUtil.isEmpty(connectList)) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + jobNodeConfig.getOutput_connect_id() + "】不存在！");
                                    }
                                    ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getOutput_connect_id(), o.getId())).findAny().orElse(null);
                                    if (null == confConnectAndConfigDto) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + jobNodeConfig.getOutput_connect_id() + "】不存在！");
                                    }
//                                    Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
                                    ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>()
                                            .eq("name", confConnectAndConfigDto.getName())
                                            .eq("tenant_id", tenantId).last(" limit 1 ")
                                    );
                                    if (null == confConnect) {
                                        throw new RRException("节点：【" + jobNodeInfo.getName() + "】里的数据源连接：【" + confConnectAndConfigDto.getName() + "】不存在！");
                                    } else {
                                        //数据源连接是否已经关联
                                        ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()).last(" limit 1 "));
                                        if (null == procConnect) {
                                            throw new RRException("【" + jobNodeInfo.getName() + "】节点,当前系统数据源【" + confConnect.getName() + "】未关联项目！");
                                        }
                                    }
                                    jobNodeConfig.setOutput_connect_id(confConnect.getId());
                                }

                                newJobNodeInfo.setJobNodeConfig(jobNodeConfig);
                                //查询对应的项目管理员
                                newJobNodeInfo.setIsImport(1);
                                jobNodeInfoService.saveJobNodeConfig(newJobNodeInfo);
                                System.out.println("导入创建节点数据：" + newJobNodeInfo + ",时间：" + System.currentTimeMillis() + ",计数个数：" + latch.getCount());
                            }
                            newJobNodeInfos.add(newJobNodeInfo);

                        } catch (Exception e) {
                            importStatus[0] = 1;
                            stringBuilder.append(jobNodeInfo.getName() + "节点创建失败：" + e.getMessage()).append("</br>");
                            //节点生成失败
                            jobNodeInfoDto.setIsGenError(1);
                            //如果当前这个节点配置保存失败，则如果有位置信息，则需要置空
                            Integer newId = jobNodeInfo.getNewId();
                            if (null != newId) {
                                jobNodeInfoMapper.updatePosXY(newId);
                            }
                            e.printStackTrace();
                        } finally {
                            //计数器减一
                            latch.countDown();
                        }
                    }
                });
                es1.shutdown();
            }
            //阻塞在这里
            latch.await();
            System.out.println("导入数据完成：" + needJobNodeInfos.size() + ",耗时：" + (System.currentTimeMillis() - startTimes));

            if (CollectionUtil.isEmpty(nodes)) {
                if (Objects.equals(1, importStatus[0])) {
                    throw new RRException(stringBuilder.toString());
                } else {
                    return;
                }
            }
            //判断这些需要保存的节点对应的配置是否保存成功
            List<JobNodeInfoDto> filtErrors = nodes.stream().filter(o -> Objects.equals(1, o.getIsGenError())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(filtErrors)) {
                stringBuilder.append("画布中存在未成功的节点,则生成工作流失败！");
                jobInfoDto.setIsGenError(1);
                throw new RRException(stringBuilder.toString());
            }
            //生成工作流和节点连线和对应的调度配置信息
            List<JobLink> jobLinks = otherWorkFlow.getJobLinks();
            JobLinkAndJobNodeDto jobLinkAndJobNodeDto = new JobLinkAndJobNodeDto();
            jobLinkAndJobNodeDto.setWorkFlowMenuId(workMenu.getId());
            jobLinkAndJobNodeDto.setProcId(procId);
            jobLinkAndJobNodeDto.setNodes(nodes);
            if (null != otherWorkFlow.getJobNodeConfig()) {
                jobLinkAndJobNodeDto.setJobNodeConfig(otherWorkFlow.getJobNodeConfig());
            }
            if (CollectionUtil.isNotEmpty(jobLinks)) {
                List<JobLinkDto> edges = new ArrayList<>();
                for (JobLink jobLink : jobLinks) {
                    JobNodeInfo srcJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobLink.getSrcNodeId())).findAny().orElse(null);
                    JobNodeInfo dstJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobLink.getDstNodeId())).findAny().orElse(null);
                    if (null == srcJobNodeInfo || null == dstJobNodeInfo) {
                        throw new RRException("源：【" + jobLink.getSrcNodeId() + "】或者目标节点：【" + jobLink.getDstNodeId() + "】不存在！");
                    }
                    JobLinkDto jobLinkDto = new JobLinkDto();
                    jobLinkDto.setMenuId(workMenu.getId());
                    jobLinkDto.setLinkeType(0);
                    jobLinkDto.setDstNodeId(dstJobNodeInfo.getNewId());
                    jobLinkDto.setSrcNodeId(srcJobNodeInfo.getNewId());
                    edges.add(jobLinkDto);
                }
                if (CollectionUtil.isNotEmpty(edges)) {
                    jobLinkAndJobNodeDto.setEdges(edges);
                }
            }
            //查询对应的项目管理员
            jobLinkAndJobNodeDto.setIsImport(1);
            iWorkMenuService.updateWorkJob(jobLinkAndJobNodeDto);
        }

        //对应节点的依赖路由配置
        if (null != jobInfoDto && CollectionUtil.isNotEmpty(jobInfoDto.getJobNodeInfos())) {
            List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
            for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
                List<JobNodeLayConfigDto> jobNodeLayConfigDtoList = jobNodeInfo.getJobNodeLayConfigDtoList();
                if (CollectionUtil.isNotEmpty(jobNodeLayConfigDtoList)) {
                    try {
                        List<JobNodeLayConfigDto> newJobNodeLayConfigDtoList = new ArrayList<>();
                        for (JobNodeLayConfigDto jobNodeLayConfigDto : jobNodeLayConfigDtoList) {
                            JobNodeLayConfigDto jobNodeLayConfigDto1 = new JobNodeLayConfigDto();
                            BeanUtils.copyProperties(jobNodeLayConfigDto, jobNodeLayConfigDto1);
                            jobNodeLayConfigDto1.setJobId(jobNodeInfo.getNewJobId());
                            JobNodeInfo upJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeLayConfigDto.getUpNodeId())).findAny().orElse(null);
                            JobNodeInfo currentJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeLayConfigDto.getCurrentNodeId())).findAny().orElse(null);
                            if (null == upJobNodeInfo || null == currentJobNodeInfo) {
                                throw new RRException("当前：【" + jobNodeLayConfigDto.getCurrentNodeId() + "】或者上级节点：【" + jobNodeLayConfigDto.getUpNodeId() + "】不存在！");
                            }
                            //新的id的替换
                            JobNodeInfo newUpJobNodeInfo = needJobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), upJobNodeInfo.getId())).findAny().orElse(null);
                            JobNodeInfo newCurrentJobNodeInfo = needJobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), currentJobNodeInfo.getId())).findAny().orElse(null);
                            if (null == newUpJobNodeInfo || null == newCurrentJobNodeInfo) {
                                throw new RRException("当前：【" + jobNodeLayConfigDto.getCurrentNodeId() + "】或者上级节点：【" + jobNodeLayConfigDto.getUpNodeId() + "】不存在！");
                            }
                            jobNodeLayConfigDto1.setUpNodeId(newUpJobNodeInfo.getNewId());
                            jobNodeLayConfigDto1.setCurrentNodeId(newCurrentJobNodeInfo.getNewId());
                            if (Objects.equals(RouteTypeEnum.COUNT.getId(), jobNodeLayConfigDto.getConfigType()) && null != jobNodeLayConfigDto.getOutputTableId()) {
                                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", jobNodeLayConfigDto.getDbName()).eq("table_name", jobNodeLayConfigDto.getTableName()));
                                if (null == tableInfo) {
                                    throw new RRException("当前系统不存在仓库表：【" + jobNodeLayConfigDto.getDbName() + "." + jobNodeLayConfigDto.getTableName() + "】");
                                }
                                jobNodeLayConfigDto1.setOutputTableId(tableInfo.getId());
                            }
                            jobNodeLayConfigDto1.setDutyUser(sysUserService.getUserId(jobNodeLayConfigDto.getDutyUserName(), ShiroUtils.getUserId().intValue()));
                            //id也要变化
                            JobNodeLayConfig jobNodeLayConfig = jobNodeLayConfigMapper.selectOne(new QueryWrapper<JobNodeLayConfig>().eq("job_id", newCurrentJobNodeInfo.getNewJobId())
                                    .eq("current_node_id", newCurrentJobNodeInfo.getNewId()).eq("up_node_id", newUpJobNodeInfo.getNewId()));
                            if (null != jobNodeLayConfig) {
                                jobNodeLayConfigDto1.setId(jobNodeLayConfig.getId());
                                newJobNodeLayConfigDtoList.add(jobNodeLayConfigDto1);
                            }
                        }
                        //需要重新生成节点信息
                        JobNodeInfo jobNodeInfo1 = newJobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeInfo.getNewId())).findAny().orElse(null);
                        if (null != jobNodeInfo1) {
                            jobNodeInfo1.setJobNodeLayConfigDtoList(newJobNodeLayConfigDtoList);
                            jobNodeInfo1.setIsImport(1);
                            jobNodeInfoService.saveJobNodeConfig(jobNodeInfo1);
                        }
                    } catch (Exception e) {
                        importStatus[0] = 1;
                        stringBuilder.append("【路由配置异常】" + e.getMessage()).append("</br>");
                    }
                }
            }
        }

        //先禁用作业流依赖，再启用作业流依赖
        if (null != workMenuLayId) {
            iWorkMenuService.closeWorkFlowJob(workMenuLayId);
            iWorkMenuService.openWorkFlowJob(workMenuLayId);
        }


        //判断是否生成失败。如果失败则直接抛出异常
        if (Objects.equals(1, importStatus[0])) {
            throw new RRException(stringBuilder.toString());
        }
    }

    private WorkMenuJobRel addWorkMenuJobRel(Integer jobNodeId, Long workMenuId, Integer procId) {
        WorkMenuJobRel workMenuJobRel = new WorkMenuJobRel();
        workMenuJobRel.setProcId(procId);
        workMenuJobRel.setWorkType(0);
        workMenuJobRel.setWorkMenuId(workMenuId);
        workMenuJobRel.setWorkFlowId(Long.valueOf(jobNodeId));
        workMenuJobRel.setCreateTime(LocalDateTime.now());
        workMenuJobRelMapper.insert(workMenuJobRel);
        return workMenuJobRel;
    }

    private JobNodeInfo addJobNodeInfo(JobNodeInfo jobNodeInfo, Integer jobId, Integer procId) {
        JobNodeInfo jobNodeInfo1 = new JobNodeInfo();
        jobNodeInfo1.setName(jobNodeInfo.getName());
        jobNodeInfo1.setTypeId(jobNodeInfo.getTypeId());
        jobNodeInfo1.setEnable(jobNodeInfo.getEnable());
        jobNodeInfo1.setCreateTime(DateTime.now());
        jobNodeInfo1.setCreatePer(sysUserService.getUserId(jobNodeInfo.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        jobNodeInfo1.setJobId(jobId);
        jobNodeInfo1.setPosX(jobNodeInfo.getPosX());
        jobNodeInfo1.setPosY(jobNodeInfo.getPosY());
        jobNodeInfo1.setProcId(procId);
        jobNodeInfo1.setIsNullRun(jobNodeInfo.getIsNullRun() == null ? 0 : jobNodeInfo.getIsNullRun());
        jobNodeInfoMapper.insert(jobNodeInfo1);
        //如果是shell类型的，还得把服务器地址也复制过去
        if (Objects.equals(JobType.SHELL.getCode(), jobNodeInfo.getTypeId())) {
            BussessConfigEntity bussessConfigEntity = bussessConfigMapper.selectOne(new QueryWrapper<BussessConfigEntity>().eq("bussess_type", 1).eq("bussess_id", jobNodeInfo1.getId()));
            if (null != bussessConfigEntity) {
                bussessConfigMapper.deleteById(bussessConfigEntity.getId());
            }
            bussessConfigEntity = new BussessConfigEntity();
            bussessConfigEntity.setBussessType(1);
            bussessConfigEntity.setBussessId(jobNodeInfo1.getId());
            bussessConfigEntity.setHostUrl(jobNodeInfo.getHostUrl());
            bussessConfigEntity.setPort(jobNodeInfo.getPort());
            bussessConfigEntity.setUsername(jobNodeInfo.getUsername());
            bussessConfigEntity.setPassword(jobNodeInfo.getPassword());
            bussessConfigEntity.setCreateTime(DateTime.now());
            bussessConfigMapper.insert(bussessConfigEntity);
        }
        return jobNodeInfo1;
    }

    private WorkMenu addWorkFlowMGTAndSubDto(WorkMenuAndLayDto otherWorkFlow, Integer procId, Long
            newParentId, Long newRootId) {
        WorkMenuDto workMenuDto = new WorkMenuDto();
        workMenuDto.setProcId(procId);
        workMenuDto.setParentId(newParentId);
        workMenuDto.setRootId(newRootId);
        workMenuDto.setWorkType(otherWorkFlow.getWorkType());
        workMenuDto.setName(otherWorkFlow.getName());
        workMenuDto.setDescName(otherWorkFlow.getDescName());
        workMenuDto.setCreateTime(LocalDateTime.now());
        workMenuDto.setCreatePer(sysUserService.getUserId(otherWorkFlow.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        return iWorkMenuService.addWorkFlowMGTAndSubMenu(workMenuDto);
    }

    private WorkMenu addDefaultWorkFlowMenu(WorkMenuAndLayDto otherWorkFlow, Integer procId, Long
            newParentId, Long
                                                    newRootId, Long workMenuNewId, Integer olderJobId) {
        WorkMenuDto workMenuDto = new WorkMenuDto();
        if (null != workMenuNewId) {
            workMenuDto.setId(workMenuNewId);
        }
        workMenuDto.setProcId(procId);
        workMenuDto.setParentId(newParentId);
        workMenuDto.setRootId(newRootId);
        workMenuDto.setWorkType(otherWorkFlow.getWorkType());
        workMenuDto.setName(otherWorkFlow.getName());
        workMenuDto.setDescName(otherWorkFlow.getDescName());
        workMenuDto.setCreateTime(LocalDateTime.now());
        workMenuDto.setCreatePer(sysUserService.getUserId(otherWorkFlow.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        workMenuDto.setOlderJobId(olderJobId);
        return iWorkMenuService.addDefaultWorkFlowMenu(workMenuDto);
    }

    private WorkMenu addRootWorkMenuDto(WorkMenuAndLayDto otherWorkFlow, Integer procId) {
        WorkMenuDto workMenuDto = new WorkMenuDto();
        workMenuDto.setProcId(procId);
        workMenuDto.setParentId(0L);
        workMenuDto.setWorkType(otherWorkFlow.getWorkType());
        workMenuDto.setName(otherWorkFlow.getName());
        workMenuDto.setDescName(otherWorkFlow.getDescName());
        workMenuDto.setCreateTime(LocalDateTime.now());
        workMenuDto.setCreatePer(sysUserService.getUserId(otherWorkFlow.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        return iWorkMenuService.addRootWorkFlowMenu(workMenuDto);
    }

    private RealTimeTaskMenuVO addRootRealWorkMenuDto(RealTimeTaskMenuAndTaskDto otherWorkFlow, Integer procId) {
        List<ProcUser> procUsers = procUserMapper.selectList(new QueryWrapper<ProcUser>().eq("proc_id", procId));
        if (CollectionUtil.isEmpty(procUsers)) {
            throw new RRException("任务创建人未关联到项目");
        }
        List<Integer> userIds = procUsers.stream().map(i -> i.getUserId()).collect(Collectors.toList());
        if (!userIds.contains(otherWorkFlow.getCreatePer())) {
            throw new RRException("任务创建人未关联到项目");
        }
        RealTimeTaskMenuVO result = new RealTimeTaskMenuVO();
        RealTimeTaskMenuSaveDto workMenuDto = new RealTimeTaskMenuSaveDto();
        workMenuDto.setProcId(procId);
        workMenuDto.setParentId(otherWorkFlow.getNewParentId());
        workMenuDto.setMenuType(otherWorkFlow.getMenuType());
        workMenuDto.setLevel(otherWorkFlow.getLevel());
        workMenuDto.setName(otherWorkFlow.getName());
        workMenuDto.setDescription(otherWorkFlow.getDescription());
        if (otherWorkFlow.getMenuType() == 2) {
            RealTimeTaskVO realTimeTaskVO = otherWorkFlow.getRealTimeTaskVO();
            workMenuDto.setTaskType(realTimeTaskVO.getTaskType());
        }
        R r = realTimeTaskMenuService.saveOrUpdate(workMenuDto);
        if (r != null & (Integer) r.get("code") == 0) {
            result = (RealTimeTaskMenuVO) r.get("data");
            RealTimeTaskMenu realTimeTaskMenu = realTimeTaskMenuMapper.selectById(result.getId());
            realTimeTaskMenu.setCreatePer(otherWorkFlow.getCreatePer());
            realTimeTaskMenuMapper.updateById(realTimeTaskMenu);
            if (otherWorkFlow.getMenuType() == 2) {
                RealTimeTaskVO realTimeTaskVO = otherWorkFlow.getRealTimeTaskVO();
                RealTimeTaskSaveDto saveDto = new RealTimeTaskSaveDto();
                BeanUtils.copyProperties(realTimeTaskVO, saveDto);
                RealTimeTask task = realTimeTaskMapper.selectOne(new QueryWrapper<RealTimeTask>().eq("menu_id", result.getId()));
                if (task != null) {
                    saveDto.setMenuId(result.getId());
                    saveDto.setId(task.getId());
                    saveDto.setRunState(3);
                    realTimeTaskService.saveOrUpdate(saveDto);
                    if (realTimeTaskVO.getConfig() != null) {
                        String config = realTimeTaskVO.getConfig().toJSONString();
                        realTimeTaskMapper.updateConfig(config, task.getMenuId());
                    }
                }
            }
        } else {
            throw new RRException("异常原因:" + r.get("msg"));
        }
        return result;
    }


    /***
     * 生成对应的菜单目录，并且记录其对应的改变
     * @param entry                   整个根目录和其下所有的子目录
     * @param newWorkMenus            新的菜单目录
     */
    private List<WorkMenuAndLayDto> genPackWorkMenus
    (Map.Entry<Long, List<WorkMenuAndLayDto>> entry, List<WorkMenu> newWorkMenus) {
        if (null != entry) {
            Long olderRootId = entry.getKey();
            List<WorkMenuAndLayDto> olderWorkMenus = entry.getValue();
            if (null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)) {
                WorkMenuAndLayDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
                if (null != workMenuAndLayDto) {
                    packTmpPathName(Arrays.asList(workMenuAndLayDto), "", olderWorkMenus);//包里面的路径名称
                    WorkMenu workMenu1 = null;
                    if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                        workMenu1 = newWorkMenus.stream().filter(workMenu -> {
                            if (Objects.equals(workMenu.getParentId(), 0L) && Objects.equals(workMenu.getName(), workMenuAndLayDto.getName())) {
                                return true;
                            }
                            return false;
                        }).findAny().orElse(null);
                    }
                    if (null == workMenu1) {
                        return olderWorkMenus;
                    } else {
                        //如果有，则添加对应的菜单id
                        List<WorkMenuAndLayDto> listWorkDtoList = new ArrayList<>();
                        workMenuAndLayDto.setNewId(workMenu1.getId());
                        workMenuAndLayDto.setNewCreatePer(workMenu1.getCreatePer());
                        workMenuAndLayDto.setNewParentId(workMenu1.getParentId());
                        workMenuAndLayDto.setNewProcId(Long.valueOf(workMenu1.getProcId()));
                        workMenuAndLayDto.setNewRootId(workMenu1.getRootId());
                        workMenuAndLayDto.setTmpPathName("/" + workMenuAndLayDto.getName());
                        listWorkDtoList.add(workMenuAndLayDto);

                        //递归其下所有的文件
                        List<WorkMenuAndLayDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
                        WorkMenu finalWorkMenu = workMenu1;
                        List<WorkMenu> newChildrens = newWorkMenus.stream().filter(workMenu -> Objects.equals(finalWorkMenu.getId(), workMenu.getParentId())).collect(Collectors.toList());
                        //遍历下面的菜单
                        if (CollectionUtil.isNotEmpty(olderChildrens)) {
                            initNewIdData(olderChildrens, newChildrens, olderWorkMenus, newWorkMenus, listWorkDtoList);
                        }
                        return listWorkDtoList;

                    }
                }
            }
        }
        return null;
    }

    /***
     * 生成对应的菜单目录，并且记录其对应的改变
     * @param entry                   整个根目录和其下所有的子目录
     * @param newWorkMenus            新的菜单目录
     */
    private List<RealTimeTaskMenuAndTaskDto> genPackRealWorkMenus
    (Integer rootId, List<RealTimeTaskMenuAndTaskDto> entry, List<RealTimeTaskMenu> newWorkMenus) {
        if (null != entry) {
            Integer olderRootId = rootId;
            List<RealTimeTaskMenuAndTaskDto> olderWorkMenus = entry;
            if (null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)) {
                RealTimeTaskMenuAndTaskDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
                if (null != workMenuAndLayDto) {
                    RealTimeTaskMenu workMenu1 = null;
                    if (CollectionUtil.isNotEmpty(newWorkMenus)) {
                        workMenu1 = newWorkMenus.stream().filter(workMenu -> {
                            if (Objects.equals(workMenu.getParentId(), 0) && Objects.equals(workMenu.getName(), workMenuAndLayDto.getName())) {
                                return true;
                            }
                            return false;
                        }).findAny().orElse(null);
                    }
                    if (null == workMenu1) {
                        List<RealTimeTaskMenuAndTaskDto> listWorkDtoList = new ArrayList<>();
                        listWorkDtoList.add(workMenuAndLayDto);
                        //递归其下所有的文件
                        List<RealTimeTaskMenuAndTaskDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
                        //遍历下面的菜单
                        initOldRealIdData(olderChildrens, olderWorkMenus, listWorkDtoList);
                        return listWorkDtoList;
                    } else {
                        //如果有，则添加对应的菜单id
                        List<RealTimeTaskMenuAndTaskDto> listWorkDtoList = new ArrayList<>();
                        workMenuAndLayDto.setNewId(Long.valueOf(workMenu1.getId()));
                        workMenuAndLayDto.setNewCreatePer(workMenu1.getCreatePer());
                        workMenuAndLayDto.setNewParentId(workMenu1.getParentId());
                        workMenuAndLayDto.setNewProcId(workMenu1.getProcId().intValue());
                        listWorkDtoList.add(workMenuAndLayDto);

                        //递归其下所有的文件
                        List<RealTimeTaskMenuAndTaskDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
                        RealTimeTaskMenu finalWorkMenu = workMenu1;
                        List<RealTimeTaskMenu> newChildrens = newWorkMenus.stream().filter(workMenu -> Objects.equals(finalWorkMenu.getId(), workMenu.getParentId())).collect(Collectors.toList());
                        //遍历下面的菜单
                        initNewRealIdData(olderChildrens, newChildrens, olderWorkMenus, newWorkMenus, listWorkDtoList);
                        return listWorkDtoList;

                    }
                }
            }
        }
        return null;
    }

    /***
     * 生成对应的菜单目录，并且记录其对应的改变
     * @param entry                   整个根目录和其下所有的子目录
     */
    private List<RealTimeTaskMenu> genPackRealWorkMenus
    (Integer rootId, List<RealTimeTaskMenu> entry) {
        if (null != entry) {
            //如果有，则添加对应的菜单id
            List<RealTimeTaskMenu> listWorkDtoList = new ArrayList<>();
            List<RealTimeTaskMenu> workMenus = entry;
            if (null != rootId && CollectionUtil.isNotEmpty(workMenus)) {
                RealTimeTaskMenu workMenuAndLayDto = workMenus.stream().filter(o -> Objects.equals(o.getId(), rootId)).findAny().orElse(null);
                if (null != workMenuAndLayDto) {
                    listWorkDtoList.add(workMenuAndLayDto);
                    //递归其下所有的文件
                    List<RealTimeTaskMenu> olderChildrens = workMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
                    //遍历下面的菜单
                    initRealIdData(olderChildrens, workMenus, listWorkDtoList);
                    return listWorkDtoList;
                }
            }
        }
        return null;
    }

    private void initNewIdData
            (List<WorkMenuAndLayDto> olderChildrens, List<WorkMenu> newChildrens, List<WorkMenuAndLayDto> olderWorkMenus, List<WorkMenu> newWorkMenus, List<WorkMenuAndLayDto> listWorkDtoList) {
        if (CollectionUtil.isEmpty(newChildrens)) {
            if (CollectionUtil.isNotEmpty(olderChildrens)) {
                for (WorkMenuAndLayDto olderChildren : olderChildrens) {
                    listWorkDtoList.add(olderChildren);
                    //还要把子目录下其他的目录也放进去
                    initAllChilds(olderWorkMenus, olderChildren.getId(), listWorkDtoList);
                }
            }
            return;
        }
        if (CollectionUtil.isNotEmpty(newChildrens) && CollectionUtil.isNotEmpty(olderChildrens)) {
            for (WorkMenuAndLayDto olderChildren : olderChildrens) {
                WorkMenu workMenu = newChildrens.stream().filter(o -> Objects.equals(o.getTmpPathName(), olderChildren.getTmpPathName())).findAny().orElse(null);
                if (null == workMenu) {
                    listWorkDtoList.add(olderChildren);
                    //还要把子目录下其他的目录也放进去
                    initAllChilds(olderWorkMenus, olderChildren.getId(), listWorkDtoList);
                } else {
                    olderChildren.setNewId(workMenu.getId());
                    olderChildren.setNewCreatePer(workMenu.getCreatePer());
                    olderChildren.setNewParentId(workMenu.getParentId());
                    olderChildren.setNewProcId(Long.valueOf(workMenu.getProcId()));
                    olderChildren.setNewRootId(workMenu.getRootId());
                    listWorkDtoList.add(olderChildren);
                    //继续递归
                    List<WorkMenuAndLayDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                    List<WorkMenu> newChildrens1 = newWorkMenus.stream().filter(workMenu1 -> Objects.equals(workMenu.getId(), workMenu1.getParentId())).collect(Collectors.toList());
                    //遍历下面的菜单
                    initNewIdData(olderChildrens1, newChildrens1, olderWorkMenus, newWorkMenus, listWorkDtoList);
                }
            }
        }

    }

    private void packTmpPathName(List<WorkMenuAndLayDto> olderChildrens, String paPath, List<WorkMenuAndLayDto> olderWorkMenus) {
        if (CollectionUtil.isEmpty(olderChildrens)) {
            return;
        }
        for (WorkMenuAndLayDto childerDto : olderChildrens) {
            String tmpName = paPath + "/" + childerDto.getName();
            childerDto.setTmpPathName(tmpName);
            //下面的子目录
            List<WorkMenuAndLayDto> cchilds = olderWorkMenus.stream().filter(o -> Objects.equals(o.getParentId(), childerDto.getId())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(cchilds)) {
                packTmpPathName(cchilds, tmpName, olderWorkMenus);
            }
        }
    }

    private void packNewTmpPathName(List<WorkMenu> newChildrens) {
        if (CollectionUtil.isEmpty(newChildrens)) {
            return;
        }
        List<WorkMenu> rootWorkFlows = newChildrens.stream().filter(o -> Objects.equals(o.getParentId(), 0L)).collect(Collectors.toList());
        if (CollectionUtil.isEmpty(rootWorkFlows)) {
            return;
        }
        packTmpsNames(rootWorkFlows, "", newChildrens);
    }

    private void packTmpsNames(List<WorkMenu> childs, String ppName, List<WorkMenu> newChildrens) {
        if (CollectionUtil.isNotEmpty(childs) && CollectionUtil.isNotEmpty(newChildrens)) {
            for (WorkMenu child : childs) {
                String tmpName = ppName + "/" + child.getName();
                child.setTmpPathName(tmpName);
                //下面的子目录
                List<WorkMenu> cchilds = newChildrens.stream().filter(o -> Objects.equals(o.getParentId(), child.getId())).collect(Collectors.toList());
                if (CollectionUtil.isNotEmpty(cchilds)) {
                    packTmpsNames(cchilds, tmpName, newChildrens);
                }
            }
        }
    }

    private void packNewRealTmpPathName(List<RealTimeTaskMenu> newChildrens) {
        if (CollectionUtil.isEmpty(newChildrens)) {
            return;
        }
        List<RealTimeTaskMenu> rootWorkFlows = newChildrens.stream().filter(o -> Objects.equals(o.getParentId(), 0L)).collect(Collectors.toList());
        if (CollectionUtil.isEmpty(rootWorkFlows)) {
            return;
        }
        packRealTmpsNames(rootWorkFlows, "", newChildrens);
    }

    private void packRealTmpsNames(List<RealTimeTaskMenu> childs, String ppName, List<RealTimeTaskMenu> newChildrens) {
        if (CollectionUtil.isNotEmpty(childs) && CollectionUtil.isNotEmpty(newChildrens)) {
            for (RealTimeTaskMenu child : childs) {
                String tmpName = ppName + "/" + child.getName();
                child.setTmpPathName(tmpName);
                //下面的子目录
                List<RealTimeTaskMenu> cchilds = newChildrens.stream().filter(o -> Objects.equals(o.getParentId(), child.getId())).collect(Collectors.toList());
                if (CollectionUtil.isNotEmpty(cchilds)) {
                    packRealTmpsNames(cchilds, tmpName, newChildrens);
                }
            }
        }
    }

    private void initAllChilds(List<WorkMenuAndLayDto> olderWorkMenus, Long id, List<WorkMenuAndLayDto> listWorkDtoList) {
        if (CollectionUtil.isNotEmpty(olderWorkMenus)) {
            List<WorkMenuAndLayDto> datas = olderWorkMenus.stream().filter(o -> Objects.equals(o.getParentId(), id)).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(datas)) {
                listWorkDtoList.addAll(datas);
                for (WorkMenuAndLayDto data : datas) {
                    initAllChilds(olderWorkMenus, data.getId(), listWorkDtoList);
                }
            }
        }
    }

    private void initNewRealIdData
            (List<RealTimeTaskMenuAndTaskDto> olderChildrens, List<RealTimeTaskMenu> newChildrens, List<RealTimeTaskMenuAndTaskDto> olderWorkMenus, List<RealTimeTaskMenu> newWorkMenus, List<RealTimeTaskMenuAndTaskDto> listWorkDtoList) {
        if (CollectionUtil.isEmpty(newChildrens)) {
            listWorkDtoList.addAll(olderChildrens);
        }
        if (CollectionUtil.isNotEmpty(newChildrens) && CollectionUtil.isNotEmpty(olderChildrens)) {
            for (RealTimeTaskMenuAndTaskDto olderChildren : olderChildrens) {
                RealTimeTaskMenu workMenu = newChildrens.stream().filter(o -> Objects.equals(o.getName(), olderChildren.getName())).findAny().orElse(null);
                if (null == workMenu) {
                    listWorkDtoList.add(olderChildren);
                } else {
                    olderChildren.setNewId(Long.valueOf(workMenu.getId()));
                    olderChildren.setNewCreatePer(workMenu.getCreatePer());
                    olderChildren.setNewParentId(workMenu.getParentId());
                    olderChildren.setNewProcId(workMenu.getProcId().intValue());
                    listWorkDtoList.add(olderChildren);
                    //继续递归
                    List<RealTimeTaskMenuAndTaskDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                    List<RealTimeTaskMenu> newChildrens1 = newWorkMenus.stream().filter(workMenu1 -> Objects.equals(workMenu.getId(), workMenu1.getParentId())).collect(Collectors.toList());
                    //遍历下面的菜单
                    initNewRealIdData(olderChildrens1, newChildrens1, olderWorkMenus, newWorkMenus, listWorkDtoList);
                }
            }
        }

    }

    private void initOldRealIdData
            (List<RealTimeTaskMenuAndTaskDto> olderChildrens, List<RealTimeTaskMenuAndTaskDto> olderWorkMenus, List<RealTimeTaskMenuAndTaskDto> listWorkDtoList) {
        if (CollectionUtil.isNotEmpty(olderChildrens)) {
            for (RealTimeTaskMenuAndTaskDto olderChildren : olderChildrens) {
                listWorkDtoList.add(olderChildren);
                //继续递归
                List<RealTimeTaskMenuAndTaskDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                //遍历下面的菜单
                initOldRealIdData(olderChildrens1, olderWorkMenus, listWorkDtoList);
            }
        }
    }

    private void initRealIdData
            (List<RealTimeTaskMenu> olderChildrens, List<RealTimeTaskMenu> olderWorkMenus, List<RealTimeTaskMenu> listWorkDtoList) {
        if (CollectionUtil.isNotEmpty(olderChildrens)) {
            for (RealTimeTaskMenu olderChildren : olderChildrens) {
                listWorkDtoList.add(olderChildren);
                //继续递归
                List<RealTimeTaskMenu> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
                //遍历下面的菜单
                initRealIdData(olderChildrens1, olderWorkMenus, listWorkDtoList);
            }
        }
    }


    @Override
    public List<String> rollbackProject(Long versionId) {
        //查询对应的版本是否存在
        BdpVersion bdpVersion = bdpVersionMapper.selectById(versionId);
        if (null == bdpVersion) {
            throw new RRException("备份的版本包不存在！");
        }
        if (!Objects.equals(VersionType.BACKUPS.getCode(), bdpVersion.getVersionType())) {
            throw new RRException("改版本包不是备份的版本包！");
        }
        //验证是否可以回滚
        if (Objects.equals(bdpVersion.getIsRock(), 0)) {
            throw new RRException("版本不能回滚！");
        }
        //根据备份文件进行备份操作
        List<String> errorList = new ArrayList<>();
        //查询到所有的为0的状态的任务
        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", bdpVersion.getUpZipPathName()));
        if (null != uploadVersionLog) {
            //验证是否完成，没有完成也不能点击回滚
            if (Objects.equals(uploadVersionLog.getImportStatus(), ImportStatusEnum.IMPORT_ING.getId())) {
                throw new RRException("版本导入还是导入中,请完成本次版本导入！");
            }
            List<BdpVersion> bdpVersions = bdpVersionMapper.selectByUpZipTime(uploadVersionLog.getProcId(), bdpVersion.getCreateTime());
            if (CollectionUtil.isNotEmpty(bdpVersions)) {
                for (BdpVersion version : bdpVersions) {
                    if (Objects.equals(version.getIsSuccessed(), 1)) {
                        continue;
                    }
                    BdpVersionProcRel bdpVersionProcRel = bdpVersionProcRelMapper.selectOne(new QueryWrapper<BdpVersionProcRel>().eq("version_id", version.getId()));
                    if (null == bdpVersionProcRel) {
                        throw new RRException("备份的版本包json资源文件异常！");
                    }
                    //读取文件
                    String dataJson = "";
                    HdfsUtil hdfsUtil = null;
                    try {
                        hdfsUtil = new HdfsUtil(bdpJobConfig);
                        String uploadPath = String.format("%s/%s/%s/%s", bdpJobConfig.getVersion(), bdpVersionProcRel.getProcId(), version.getId(), version.getUpZipPathName() + ".json");
                        FSDataInputStream fsDataInputStream = hdfsUtil.readFile(uploadPath);
                        dataJson = CompressUtil.readJsonFile(fsDataInputStream);
                        hdfsUtil.close();
                    } catch (Exception e) {
                        if (null != hdfsUtil) {
                            hdfsUtil.close();
                        }
                        log.error("备份文件异常！error:{}", e.getMessage());
                        throw new RRException("备份文件异常！");
                    } finally {
                        if (null != hdfsUtil) {
                            hdfsUtil.close();
                        }
                    }
                    if (StringUtils.isEmpty(dataJson)) {
                        throw new RRException("备份的版本的资源文件数据有误！");
                    }
                    //解析备份的版本文件
                    CopyAllDataDto copyAllDataDto = beanDataChangeService.analyCopyDataList(dataJson);

                    //回滚
                    copyRollbackAllData(copyAllDataDto, version.getUpZipPathName(), errorList);
                }
                //修改对应的状态
                if (bdpVersions.size() > 1) {
                    bdpVersionMapper.batchUpdateIsRocks(bdpVersions.stream().limit(bdpVersions.size() - 1).map(BdpVersion::getUpZipPathName).collect(Collectors.toSet()));
                }
            }
        }
        //老版本的回滚
//        if(Boolean.FALSE){
//            copyRollbackData(copyAllDataDto,errorList);
//        }

        if (CollectionUtil.isNotEmpty(errorList)) {
            bdpVersion.setIsSuccessed(2);
        } else {
            bdpVersion.setIsSuccessed(1);
        }

        bdpVersionMapper.updateById(bdpVersion);

        return errorList;
    }


    private void copyRollbackAllData(CopyAllDataDto copyAllDataDto, String
            upZipPathName, List<String> errorList) {
        if (StringUtils.isNotEmpty(upZipPathName)) {
            //查询到对应的上传的版本包
            UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", upZipPathName));
            if (null == uploadVersionLog) {
                errorList.add("备份的版本不存在！");
                return;
            }
//            //如果是同一个环境同一个工程，则直接不需要回滚
//            String zipEnv = uploadVersionLog.getUpZipEnv();
//            String activeProfile = SpringContextUtil.getActiveProfile();
//            //如果是同环境并且是同一个工程
//            if(Objects.equals(zipEnv, activeProfile) && Objects.equals(uploadVersionLog.getProcId(),uploadVersionLog.getOlderProcId())){
//                return;
//            }
            //先查询到对应的工作流和工作流依赖（先停止）
            List<UploadVersionWorkflowResultLog> uploadVersionWorkflowResultLogs =
                    uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                            .eq("upload_version_log_id", uploadVersionLog.getId())
                            .in("import_type", 0, 1));
            List<UploadVersionWorkflowResultLog> otherUploadVersionWorkflowResultLogs =
                    uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                            .eq("upload_version_log_id", uploadVersionLog.getId())
                            .eq("import_type", 2));
            List<UploadVersionWorkflowResultLog> workflowJobs = new ArrayList<>();
            List<UploadVersionWorkflowResultLog> workflowlays = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(uploadVersionWorkflowResultLogs)) {
                uploadVersionWorkflowResultLogs.forEach(o -> {
                    if (Objects.equals(o.getImportType(), 1)) {
                        workflowlays.add(o);
                    } else {
                        workflowJobs.add(o);
                    }
                });
                //停止工作流依赖
                if (CollectionUtil.isNotEmpty(workflowlays)) {
                    //如果是成功的才可以停止
                    List<UploadVersionWorkflowResultLog> needStops = workflowlays.stream().filter(o -> (!Objects.equals(o.getNewJobId(), null) && !Objects.equals(o.getNewJobId(), 0L))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(needStops)) {
                        stopWorkflowlays(needStops, errorList);
                    }
                }
                //停止工作流
                if (CollectionUtil.isNotEmpty(workflowJobs)) {
                    //如果是成功的，则可以停止
                    List<UploadVersionWorkflowResultLog> needStops = workflowJobs.stream().filter(o -> (!Objects.equals(o.getNewJobId(), null) && !Objects.equals(o.getNewJobId(), 0L))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(needStops)) {
                        stopWorkflowJobs(needStops, errorList);
                    }
                }
            }
            //不成功直接返回
            if (CollectionUtil.isNotEmpty(errorList)) {
                return;
            }

            //查询数据源连接和回滚数据源
            List<UploadVersionConnectResultLog> uploadVersionConnectResultLogs = uploadVersionConnectResultLogMapper
                    .selectList(new QueryWrapper<UploadVersionConnectResultLog>()
                            .eq("upload_version_log_id", uploadVersionLog.getId())
                            .isNotNull("new_connect_data_id")
                            .ne("new_connect_data_id", 0));
            if (CollectionUtil.isNotEmpty(uploadVersionConnectResultLogs)) {
                List<UploadVersionConnectResultLog> updateConnects = new ArrayList<>(uploadVersionConnectResultLogs.size());
                List<UploadVersionConnectResultLog> addConnects = new ArrayList<>(uploadVersionConnectResultLogs.size());
                uploadVersionConnectResultLogs.forEach(o -> {
                    if (Objects.equals(o.getIsExit(), 1)) {
                        updateConnects.add(o);
                    } else {
                        addConnects.add(o);
                    }
                });
                //回滚数据源连接
                try {
                    rollbackConnectListsToOlders(copyAllDataDto, addConnects, updateConnects, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), uploadVersionLog.getUpZipEnv());
                } catch (Exception e) {
                    log.error("回滚数据源失败!error:{}", e.getMessage());
                    errorList.add(e.getMessage());
                }
            }
            //不成功直接返回
            if (CollectionUtil.isNotEmpty(errorList)) {
                return;
            }

            //查询数据仓库和回滚数据仓库
            List<UploadVersionTableResultLog> uploadVersionTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>()
                    .eq("upload_version_log_id", uploadVersionLog.getId())
                    .isNotNull("new_table_data_id")
                    .ne("new_table_data_id", 0).eq("table_type", 1));
            if (CollectionUtil.isNotEmpty(uploadVersionTableResultLogs)) {
                List<UploadVersionTableResultLog> updateTables = new ArrayList<>(uploadVersionTableResultLogs.size());
                List<UploadVersionTableResultLog> addTables = new ArrayList<>(uploadVersionTableResultLogs.size());
                uploadVersionTableResultLogs.forEach(o -> {
                    if (Objects.equals(o.getIsExit(), 1)) {
                        updateTables.add(o);
                    } else {
                        addTables.add(o);
                    }
                });
                //回滚仓库
                try {
                    rollbackTableListsToOlders(copyAllDataDto, addTables, updateTables, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), uploadVersionLog.getUpZipEnv());
                } catch (Exception e) {
                    log.error("回滚数据仓库失败!error:{}", e.getMessage());
                    errorList.add(e.getMessage());
                }
            }
            //查询实时表和回滚实时表
            List<UploadVersionTableResultLog> uploadVersionRealTableResultLogs = uploadVersionTableResultLogMapper.selectList(new QueryWrapper<UploadVersionTableResultLog>()
                    .eq("upload_version_log_id", uploadVersionLog.getId())
                    .isNotNull("new_table_data_id")
                    .ne("new_table_data_id", 0).eq("table_type", 2));
            if (CollectionUtil.isNotEmpty(uploadVersionRealTableResultLogs)) {
                List<UploadVersionTableResultLog> updateTables = new ArrayList<>(uploadVersionRealTableResultLogs.size());
                List<UploadVersionTableResultLog> addTables = new ArrayList<>(uploadVersionRealTableResultLogs.size());
                uploadVersionRealTableResultLogs.forEach(o -> {
                    if (Objects.equals(o.getIsExit(), 1)) {
                        updateTables.add(o);
                    } else {
                        addTables.add(o);
                    }
                });
                //回滚仓库
                try {
                    rollbackRealTableListsToOlders(copyAllDataDto, addTables, updateTables, uploadVersionLog.getProcId(), uploadVersionLog.getImportChangeRole(), uploadVersionLog.getUpZipEnv());
                } catch (Exception e) {
                    log.error("回滚实时表失败!error:{}", e.getMessage());
                    errorList.add(e.getMessage());
                }
            }
            //不成功直接返回
            if (CollectionUtil.isNotEmpty(errorList)) {
                return;
            }

            //回滚对应的工作流和工作流依赖（再启用对应的数据）
            try {
                rollbackWorkflowAndLays(copyAllDataDto, workflowJobs, workflowlays, otherUploadVersionWorkflowResultLogs, uploadVersionLog.getProcId());
            } catch (Exception e) {
                log.error("回滚工作流和工作流依赖失败!error:{}", e.getMessage());
                errorList.add(e.getMessage());
            }
            //先查询到对应的工作流和工作流依赖（先停止）
            List<UploadVersionWorkflowResultLog> uploadVersionRealWorkflowResultLogs =
                    uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                            .eq("upload_version_log_id", uploadVersionLog.getId())
                            .eq("import_type", 3));
            List<UploadVersionWorkflowResultLog> otherUploadVersionRealWorkflowResultLogs =
                    uploadVersionWorkflowResultLogMapper.selectList(new QueryWrapper<UploadVersionWorkflowResultLog>()
                            .eq("upload_version_log_id", uploadVersionLog.getId())
                            .eq("import_type", 4));
            //回滚对应的实时任务和实时任务菜单（再启用对应的数据）
            try {
                rollbackRealWorkflowAndLays(copyAllDataDto, uploadVersionRealWorkflowResultLogs, otherUploadVersionRealWorkflowResultLogs, uploadVersionLog.getProcId());
            } catch (Exception e) {
                log.error("回滚工作流和工作流依赖失败!error:{}", e.getMessage());
                errorList.add(e.getMessage());
            }
        }

    }

    /***
     * 回滚工作流和工作流依赖
     * @param copyAllDataDto 备份的数据
     * @param workflowJobs   作业流
     * @param workflowlays  作业流依赖
     * @param otherUploadVersionWorkflowResultLogs
     * @param procId        工程id
     */
    @Transactional(rollbackFor = Exception.class)
    public void rollbackWorkflowAndLays(CopyAllDataDto
                                                copyAllDataDto, List<UploadVersionWorkflowResultLog> workflowJobs, List<UploadVersionWorkflowResultLog> workflowlays, List<UploadVersionWorkflowResultLog> otherUploadVersionWorkflowResultLogs, Integer
                                                procId) {
        List<UploadVersionWorkflowResultLog> addWorkFlowJobs = new ArrayList<>();
        List<UploadVersionWorkflowResultLog> addWorkFlowLays = new ArrayList<>();
        List<UploadVersionWorkflowResultLog> updateWorkFlowJobs = new ArrayList<>();
        List<UploadVersionWorkflowResultLog> updateWorkFlowLays = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(workflowJobs)) {
            workflowJobs.forEach(o -> {
                if (Objects.equals(o.getIsExit(), 1)) {
                    updateWorkFlowJobs.add(o);
                } else {
                    addWorkFlowJobs.add(o);
                }
            });
        }
        if (CollectionUtil.isNotEmpty(workflowlays)) {
            workflowlays.forEach(o -> {
                if (Objects.equals(o.getIsExit(), 1)) {
                    updateWorkFlowLays.add(o);
                } else {
                    addWorkFlowLays.add(o);
                }
            });
        }

        //新增的工作流依赖和工作流(直接删除)
        if (CollectionUtil.isNotEmpty(addWorkFlowLays)) {
            deleteAddWorkflowLays(addWorkFlowLays);
        }
        if (CollectionUtil.isNotEmpty(addWorkFlowJobs)) {
            deleteAddWorkflows(addWorkFlowJobs);
        }
        if (CollectionUtil.isNotEmpty(otherUploadVersionWorkflowResultLogs)) {
            //删除对应的父级菜单（如果是新增的话）
            deleteAddMenus(copyAllDataDto, otherUploadVersionWorkflowResultLogs);
        }

        //编辑的工作流和工作流依赖（需要修改）
        updateWorkFlowAndLays(copyAllDataDto, updateWorkFlowJobs, updateWorkFlowLays);


    }

    /***
     * 回滚实时任务
     * @param copyAllDataDto 备份的数据
     * @param workflowJobs   实时任务
     * @param otherUploadVersionWorkflowResultLogs
     * @param procId        工程id
     */
    @Transactional(rollbackFor = Exception.class)
    public void rollbackRealWorkflowAndLays(CopyAllDataDto
                                                    copyAllDataDto, List<UploadVersionWorkflowResultLog> workflowJobs, List<UploadVersionWorkflowResultLog> otherUploadVersionWorkflowResultLogs, Integer
                                                    procId) {
        List<UploadVersionWorkflowResultLog> addWorkFlowJobs = new ArrayList<>();
        List<UploadVersionWorkflowResultLog> updateWorkFlowJobs = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(workflowJobs)) {
            workflowJobs.forEach(o -> {
                if (Objects.equals(o.getIsExit(), 1)) {
                    updateWorkFlowJobs.add(o);
                } else {
                    addWorkFlowJobs.add(o);
                }
            });
        }

        //新增的实时任务(直接删除)
        if (CollectionUtil.isNotEmpty(addWorkFlowJobs)) {
            deleteAddRealWorkflows(addWorkFlowJobs);
        }
        if (CollectionUtil.isNotEmpty(otherUploadVersionWorkflowResultLogs)) {
            //删除对应的父级菜单（如果是新增的话）
            deleteAddRealMenus(copyAllDataDto, otherUploadVersionWorkflowResultLogs);
        }

        //编辑的实时任务（需要修改）
        updateRealWorkFlow(copyAllDataDto, updateWorkFlowJobs);


    }

    private void deleteAddMenus(CopyAllDataDto
                                        copyAllDataDto, List<UploadVersionWorkflowResultLog> otherUploadVersionWorkflowResultLogs) {
        if (CollectionUtil.isEmpty(otherUploadVersionWorkflowResultLogs)) {
            return;
        }
        List<UploadVersionWorkflowResultLog> filtDelets = otherUploadVersionWorkflowResultLogs.stream().filter(o -> (Objects.equals(0, o.getIsExit())
                && !Objects.equals(o.getNewWorkflowDataId(), null)
                && !Objects.equals(o.getNewWorkflowDataId(), 0L))).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(filtDelets)) {
            //删除之前看是否，自己有手动新建工作流和工作流依赖
            List<WorkMenu> workMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>()
                    .eq("proc_id", copyAllDataDto.getProcId()));
            if (CollectionUtil.isNotEmpty(workMenus)) {
                List<WorkMenu> workflows = new ArrayList<>();
                List<WorkMenu> workflowlays = new ArrayList<>();
                List<WorkMenu> others = new ArrayList<>();
                List<WorkMenu> allWorkMenus = copyAllDataDto.getAllWorkMenus();
                Set<Long> ids = new HashSet<>();
                if (CollectionUtil.isNotEmpty(allWorkMenus)) {
                    ids.addAll(allWorkMenus.stream().map(WorkMenu::getId).collect(Collectors.toSet()));
                }
                workMenus.forEach(o -> {
                    if (!ids.contains(o.getId())) {
                        if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())) {
                            workflows.add(o);
                        } else if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())) {
                            workflowlays.add(o);
                        } else {
                            others.add(o);
                        }
                    }
                });
                //停止工作流依赖，并且删除工作流依赖
                if (CollectionUtil.isNotEmpty(workflowlays)) {
                    for (WorkMenu workMenu : workflowlays) {
                        WorkFlowDep workFlowDep = workFlowDepMapper.selectOne(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", workMenu.getId()));
                        if (null != workFlowDep) { //防止重复回滚
                            if (Objects.equals(workFlowDep.getJobLayStatus(), 1)) {
                                String workLayName = null == workMenu ? "" : workMenu.getName();
                                try {
                                    iWorkMenuService.closeWorkFlowJob(workFlowDep.getWorkMenuId());
                                } catch (Exception e) {
                                    log.error("禁用工作流依赖【" + workLayName + "】异常！error:{}", e.getMessage());
                                }
                            }
                        }
                        delworkflowlaysByMenuId(workFlowDep);
                    }
                }

                //停止工作流，并且删除工作流
                if (CollectionUtil.isNotEmpty(workflows)) {
                    for (WorkMenu workMenu : workflows) {
                        WorkMenuJobRel workMenuJobRel = workMenuJobRelMapper.selectOne(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 1).eq("work_menu_id", workMenu.getId()));
                        if (null != workMenuJobRel) {
                            JobInfo jobInfo = jobInfoMapper.selectById(workMenuJobRel.getWorkFlowId());
                            if (null != jobInfo) {
                                killJob(jobInfo);
                                delJob(workMenu);
                            }
                        }
                    }
                }
                //删除其他的目录结构
                if (CollectionUtil.isNotEmpty(others)) {
                    workMenuMapper.deleteBatchIds(others.stream().map(WorkMenu::getId).collect(Collectors.toList()));
                }
            }
            workMenuMapper.deleteBatchIds(filtDelets.stream().map(UploadVersionWorkflowResultLog::getNewWorkflowDataId).collect(Collectors.toList()));
        }
    }

    private void deleteAddRealMenus(CopyAllDataDto
                                            copyAllDataDto, List<UploadVersionWorkflowResultLog> otherUploadVersionWorkflowResultLogs) {
        if (CollectionUtil.isEmpty(otherUploadVersionWorkflowResultLogs)) {
            return;
        }
        List<UploadVersionWorkflowResultLog> filtDelets = otherUploadVersionWorkflowResultLogs.stream().filter(o -> (Objects.equals(0, o.getIsExit())
                && !Objects.equals(o.getNewWorkflowDataId(), null)
                && !Objects.equals(o.getNewWorkflowDataId(), 0L))).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(filtDelets)) {
            //删除之前看是否，自己有手动新建工作流和工作流依赖
            List<RealTimeTaskMenu> workMenus = realTimeTaskMenuMapper.selectList(new QueryWrapper<RealTimeTaskMenu>()
                    .eq("proc_id", copyAllDataDto.getProcId()).eq("state", 1));
            if (CollectionUtil.isNotEmpty(workMenus)) {
                List<RealTimeTaskMenu> workflows = new ArrayList<>();
                List<RealTimeTaskMenu> others = new ArrayList<>();
                List<RealTimeTaskMenu> allWorkMenus = copyAllDataDto.getAllRealWorkMenus();
                Set<Integer> ids = new HashSet<>();
                if (CollectionUtil.isNotEmpty(allWorkMenus)) {
                    ids.addAll(allWorkMenus.stream().map(RealTimeTaskMenu::getId).collect(Collectors.toSet()));
                }
                workMenus.forEach(o -> {
                    if (!ids.contains(o.getId())) {
                        if (Objects.equals(o.getMenuType(), 2)) {
                            workflows.add(o);
                        } else {
                            others.add(o);
                        }
                    }
                });

                //删除实时任务
                if (CollectionUtil.isNotEmpty(workflows)) {
                    for (RealTimeTaskMenu workMenu : workflows) {
                        delRealJob(workMenu);
                    }
                }
                //删除其他的目录结构
                if (CollectionUtil.isNotEmpty(others)) {
                    realTimeTaskMenuMapper.deleteBatchIds(others.stream().map(RealTimeTaskMenu::getId).collect(Collectors.toList()));
                }
            }
            realTimeTaskMenuMapper.deleteBatchIds(filtDelets.stream().map(UploadVersionWorkflowResultLog::getNewWorkflowDataId).collect(Collectors.toList()));
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateWorkFlowAndLays(CopyAllDataDto copyAllDataDto,
                                      List<UploadVersionWorkflowResultLog> updateWorkFlowJobs,
                                      List<UploadVersionWorkflowResultLog> updateWorkFlowLays) {
        //先删除已经有的，再新建
        if (null != copyAllDataDto) {
            //递归生成目录和工作流和工作流依赖
            List<WorkMenu> allWorkMenus = copyAllDataDto.getAllWorkMenus();
            if (CollectionUtil.isNotEmpty(allWorkMenus)) {
                Map<Long, List<WorkMenu>> rootGroupMaps = allWorkMenus.stream().collect(Collectors.groupingBy(WorkMenu::getRootId));
                for (Map.Entry<Long, List<WorkMenu>> entry : rootGroupMaps.entrySet()) {
                    //先挑选对应的这个根目录的工作流
                    if (CollectionUtil.isNotEmpty(updateWorkFlowJobs)) {
                        List<UploadVersionWorkflowResultLog> filtWorkflows = updateWorkFlowJobs.stream().filter(o -> Objects.equals(o.getExitRootId(), entry.getKey())).collect(Collectors.toList());
                        if (CollectionUtil.isNotEmpty(filtWorkflows)) {
                            updateWorkFlowJobs(filtWorkflows, entry.getValue(), copyAllDataDto);
                        }
                    }
                    //挑选出对应根目录下的工作流依赖
                    if (CollectionUtil.isNotEmpty(updateWorkFlowLays)) {
                        List<UploadVersionWorkflowResultLog> filtWorkflowLays = updateWorkFlowLays.stream().filter(o -> Objects.equals(o.getExitRootId(), entry.getKey())).collect(Collectors.toList());
                        if (CollectionUtil.isNotEmpty(filtWorkflowLays)) {
                            updateWorkFlowLays(filtWorkflowLays, entry.getValue(), copyAllDataDto);
                        }
                    }
                }
            }
        }


    }

    @Transactional(rollbackFor = Exception.class)
    public void updateRealWorkFlow(CopyAllDataDto copyAllDataDto,
                                   List<UploadVersionWorkflowResultLog> updateWorkFlowJobs) {
        //先删除已经有的，再新建
        if (null != copyAllDataDto) {
            //递归生成目录和实时任务
            List<RealTimeTaskMenu> allWorkMenus = copyAllDataDto.getAllRealWorkMenus();
            if (CollectionUtil.isNotEmpty(allWorkMenus)) {
                List<RealTimeTaskMenu> rootWorkMenuLists = allWorkMenus.stream().filter(i -> i.getParentId() == 0).collect(Collectors.toList());
                for (RealTimeTaskMenu entry : rootWorkMenuLists) {
                    List<RealTimeTaskMenu> tempList = genPackRealWorkMenus(entry.getId(), allWorkMenus);
                    if (CollectionUtil.isNotEmpty(tempList)) {
                        //先挑选对应的这个根目录的工作流
                        if (CollectionUtil.isNotEmpty(updateWorkFlowJobs)) {
                            List<UploadVersionWorkflowResultLog> filtWorkflows = updateWorkFlowJobs.stream().filter(o -> Objects.equals(o.getExitRootId(), Long.valueOf(entry.getId()))).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(filtWorkflows)) {
                                updateRealWorkFlowJobs(filtWorkflows, tempList, copyAllDataDto);
                            }
                        }
                    }
                }
            }
        }


    }

    private void updateWorkFlowLays
            (List<UploadVersionWorkflowResultLog> filtWorkflowLays, List<WorkMenu> rootAllWorkMenus, CopyAllDataDto
                    copyAllDataDto) {
        if (CollectionUtil.isNotEmpty(filtWorkflowLays)) {
            //先删除新建的，再还原
            List<UploadVersionWorkflowResultLog> temps = new ArrayList<>();
            for (UploadVersionWorkflowResultLog filtWorkflow : filtWorkflowLays) {
                temps.clear();
                temps.add(filtWorkflow);
                deleteAddWorkflowLays(temps);
                WorkMenu workMenu = rootAllWorkMenus.stream().filter(o -> Objects.equals(o.getId(), filtWorkflow.getExitWorkflowId())).findAny().orElse(null);
                if (null != workMenu) {
                    //新增工作流依赖的菜单
                    workMenuMapper.insertById(workMenu);
                    List<WorkFlowDep> allWorkFlowDeps = copyAllDataDto.getAllWorkFlowDeps();
                    if (CollectionUtil.isNotEmpty(allWorkFlowDeps)) {
                        WorkFlowDep workFlowDep = allWorkFlowDeps.stream().filter(o -> Objects.equals(o.getWorkMenuId(), workMenu.getId())).findAny().orElse(null);
                        if (null != workFlowDep) {
                            //清空运行数据
                            workFlowDepMapper.insertWorkFlowDep(workFlowDep);
                            //生成对应的虚拟化开始节点和结束节点的shell
                            iWorkMenuService.saveStartJobNodeAndEndJobNode(workMenu.getProcId().longValue(), workFlowDep.getId().intValue(), WorkFlowType.WORKFLOW_LAY.getCode());
                            List<WorkMenuJobRel> allWorkMenuJobRels = copyAllDataDto.getAllWorkMenuJobRels();

                            //先编辑保存连线和配置信息
                            JobLinkAndJobDto jobLinkAndJobDto = new JobLinkAndJobDto();
                            jobLinkAndJobDto.setWorkFlowMenuId(workFlowDep.getWorkMenuId());
                            jobLinkAndJobDto.setProcId(workFlowDep.getProcId());
                            List<JobLink> allJobLinks = copyAllDataDto.getAllJobLinks();
                            if (CollectionUtil.isNotEmpty(allJobLinks)) {
                                List<JobLink> jobLinks = allJobLinks.stream().filter(o -> (Objects.equals(o.getMenuId(), workFlowDep.getWorkMenuId()) && Objects.equals(o.getLinkeType(), 1))).collect(Collectors.toList());
                                jobLinkAndJobDto.setEdges(PojoUtils.listConvert(JobLinkDto.class, jobLinks));
                            }
                            List<WorkMenuJobRel> workMenuJobRelJobs = allWorkMenuJobRels.stream().filter(o -> (Objects.equals(2, o.getWorkType())
                                    && Objects.equals(workFlowDep.getWorkMenuId(), o.getWorkMenuId()))).collect(Collectors.toList());
                            //查询到对应的所有的jobInfo的信息（并且其还有位置的）
                            if (CollectionUtil.isNotEmpty(workMenuJobRelJobs)) {
                                Set<Integer> jobIds = new HashSet<>();
                                workMenuJobRelJobs.forEach(o -> {
                                    jobIds.add(o.getWorkFlowId().intValue());
                                });
                                List<JobInfoDto> jobInfoDtos = jobInfoMapper.selectListByIds(jobIds);
                                if (CollectionUtil.isNotEmpty(jobInfoDtos)) {
                                    jobLinkAndJobDto.setNodes(jobInfoDtos);
                                }
                            }
                            List<JobNodeConf> allJobMenusConfs = copyAllDataDto.getAllJobMenusConfs();
                            if (CollectionUtil.isNotEmpty(allJobMenusConfs)) {
                                List<JobNodeConf> jobNodeConfs = allJobMenusConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), workFlowDep.getWorkMenuId().intValue())).collect(Collectors.toList());
                                if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
                                    JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfs, 1);
                                    if (null != jobNodeConfig) {
                                        jobLinkAndJobDto.setJobNodeConfig(jobNodeConfig);
                                    }
                                }
                            }
                            jobLinkAndJobDto.setIsImport(1);
                            try {
                                iWorkMenuService.updateWorkFlow(jobLinkAndJobDto, Boolean.FALSE);
                            } catch (Exception e) {
                                log.error("编辑保存作业流依赖【" + workFlowDep.getWorkMenuId() + "】异常！error:{}", e.getMessage());
                                throw new RRException("编辑保存作业流依赖【" + workFlowDep.getWorkMenuId() + "】异常！error:" + e.getMessage());
                            }

                            //再修改其启用禁用状态
                            WorkFlowDep workFlowDep1 = workFlowDepMapper.selectById(workFlowDep.getId());
                            if (null != workFlowDep1 && !Objects.equals(workFlowDep1.getJobLayStatus(), workFlowDep.getJobLayStatus())) {
                                try {
                                    iWorkMenuService.openWorkFlowJob(workFlowDep1.getWorkMenuId());
                                } catch (Exception e) {
                                    log.error("启用作业流依赖【" + workFlowDep1.getWorkMenuId() + "】异常！error:{}", e.getMessage());
                                    throw new RRException("启用作业流依赖【" + workFlowDep1.getWorkMenuId() + "】异常！error:" + e.getMessage());
                                }
                            }
                        }
                    }
                }

            }
        }
    }

    private void updateWorkFlowJobs
            (List<UploadVersionWorkflowResultLog> filtWorkflows, List<WorkMenu> rootAllWorkMenus, CopyAllDataDto
                    copyAllDataDto) {
        if (CollectionUtil.isNotEmpty(filtWorkflows)) {
            //先删除新建的，再还原
            List<UploadVersionWorkflowResultLog> temps = new ArrayList<>();
            for (UploadVersionWorkflowResultLog filtWorkflow : filtWorkflows) {
                temps.clear();
                temps.add(filtWorkflow);
                deleteAddWorkflows(filtWorkflows);
                WorkMenu workMenu = rootAllWorkMenus.stream().filter(o -> Objects.equals(o.getId(), filtWorkflow.getExitWorkflowId())).findAny().orElse(null);
                if (null != workMenu) {
                    //新增工作流的菜单
                    workMenuMapper.insertById(workMenu);
                    // 生成对应的job和jobNode
                    List<WorkMenuJobRel> allWorkMenuJobRels = copyAllDataDto.getAllWorkMenuJobRels();
                    if (CollectionUtil.isNotEmpty(allWorkMenuJobRels)) {
                        try {
                            WorkMenuJobRel workMenuJobRel = allWorkMenuJobRels.stream().filter(o ->
                                    (Objects.equals(o.getWorkType(), 1) && Objects.equals(o.getWorkMenuId(), workMenu.getId()))).findAny().orElse(null);
                            if (null != workMenuJobRel) {
                                iWorkMenuJobRelService.saveOrUpdate(workMenuJobRel);
                                // 虚拟化一个开始节点和一个结束节点，并且保存到hdfs上
                                iWorkMenuService.saveStartNodeAndEndNode(workMenu.getProcId().longValue(), workMenuJobRel.getWorkFlowId().intValue(), WorkFlowType.WORKFLOW.getCode());
                                // 新增任务
                                List<JobInfo> allJobInfos = copyAllDataDto.getAllJobInfos();
                                if (CollectionUtil.isNotEmpty(allJobInfos)) {
                                    JobInfo jobInfo = allJobInfos.stream().filter(o -> Objects.equals(o.getId(), workMenuJobRel.getWorkFlowId().intValue())).findAny().orElse(null);
                                    if (null != jobInfo) {
                                        //任务信息需要置空
                                        jobInfoMapper.insertJobInfo(jobInfo);
                                        //新增节点信息
                                        List<JobNodeInfo> allJobNodeInfos = copyAllDataDto.getAllJobNodeInfos();
                                        if (CollectionUtil.isNotEmpty(allJobNodeInfos)) {
                                            List<JobNodeInfo> jobNodes = allJobNodeInfos.stream().filter(o -> Objects.equals(o.getJobId(), jobInfo.getId())).collect(Collectors.toList());
                                            if (CollectionUtil.isNotEmpty(jobNodes)) {
                                                //节点关联关系
                                                List<WorkMenuJobRel> jobNodeRels = allWorkMenuJobRels.stream().filter(o -> Objects.equals(o.getWorkType(), 0)).collect(Collectors.toList());
                                                if (CollectionUtil.isNotEmpty(jobNodeRels)) {
                                                    for (JobNodeInfo jobNode : jobNodes) {
                                                        WorkMenuJobRel workMenuJobRel1 = jobNodeRels.stream().filter(o -> Objects.equals(o.getWorkFlowId().intValue(), jobNode.getId())).findAny().orElse(null);
                                                        if (null != workMenuJobRel1) {
                                                            workMenuJobRelMapper.batchInsert(Arrays.asList(workMenuJobRel1));
                                                        }
                                                    }
                                                }
                                                for (JobNodeInfo jobNode : jobNodes) {
                                                    //任务信息需要清空
                                                    jobNodeInfoMapper.insertJobNode(jobNode);
                                                    //如果是shell,还得修改对应的配置
                                                    BussessConfigEntity bussessConfigEntity = bussessConfigMapper.selectOne(new QueryWrapper<BussessConfigEntity>().eq("bussess_type", 1).eq("bussess_id", jobNode.getId()));
                                                    if (null != bussessConfigEntity) {
                                                        bussessConfigMapper.deleteById(bussessConfigEntity.getId());
                                                    }
                                                    bussessConfigEntity = new BussessConfigEntity();
                                                    bussessConfigEntity.setBussessType(1);
                                                    bussessConfigEntity.setBussessId(jobNode.getId());
                                                    bussessConfigEntity.setHostUrl(jobNode.getHostUrl());
                                                    bussessConfigEntity.setPort(jobNode.getPort());
                                                    bussessConfigEntity.setUsername(jobNode.getUsername());
                                                    bussessConfigEntity.setPassword(jobNode.getPassword());
                                                    bussessConfigEntity.setCreateTime(new Date());
                                                    bussessConfigMapper.insert(bussessConfigEntity);

                                                    //新增节点的配置信息
                                                    List<JobNodeConf> allJobNodeConfs = copyAllDataDto.getAllJobNodeConfs();
                                                    if (CollectionUtil.isNotEmpty(allJobNodeConfs)) {
                                                        List<JobNodeConf> jobNodeConfings = allJobNodeConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), jobNode.getId())).collect(Collectors.toList());
                                                        JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfings, 0);
                                                        jobNode.setProcId(jobInfo.getProcId());
                                                        if (null != jobNodeConfig) {
                                                            jobNode.setJobNodeConfig(jobNodeConfig);
                                                            jobNode.setIsImport(1);
                                                            try {
                                                                jobNodeInfoService.saveJobNodeConfig(jobNode);
                                                            } catch (Exception e) {
                                                                log.error("生成节点配置信息异常！error:{}", e.getMessage());
                                                                throw new RRException(e.getMessage());
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        //重新编辑保存任务(主要是连线)
                                        JobLinkAndJobNodeDto jobLinkAndJobNodeDto = new JobLinkAndJobNodeDto();
                                        jobLinkAndJobNodeDto.setWorkFlowMenuId(workMenu.getId());
                                        jobLinkAndJobNodeDto.setProcId(workMenu.getProcId());
                                        List<JobLink> allJobLinks = copyAllDataDto.getAllJobLinks();
                                        if (CollectionUtil.isNotEmpty(allJobLinks)) {
                                            List<JobLink> jobLinks = allJobLinks.stream().filter(o -> (Objects.equals(o.getMenuId(), workMenu.getId()) && Objects.equals(o.getLinkeType(), 0))).collect(Collectors.toList());
                                            jobLinkAndJobNodeDto.setEdges(PojoUtils.listConvert(JobLinkDto.class, jobLinks));
                                        }
                                        if (CollectionUtil.isNotEmpty(allJobNodeInfos)) {
                                            List<JobNodeInfo> jobNodes = allJobNodeInfos.stream().filter(o -> (Objects.equals(o.getJobId(), jobInfo.getId()) && null != o.getPosX())).collect(Collectors.toList());
                                            jobLinkAndJobNodeDto.setNodes(PojoUtils.listConvert(JobNodeInfoDto.class, jobNodes));
                                            if (CollectionUtil.isNotEmpty(jobNodes)) {
                                                //初始化需要路由重新保存的节点信息
                                                List<JobNodeLayConfig> allJobNodeLayCongigs = copyAllDataDto.getAllJobNodeLayCongigs();
                                                if (CollectionUtil.isNotEmpty(allJobNodeLayCongigs)) {
                                                    List<JobNodeLayConfig> jobNodeLays = allJobNodeLayCongigs.stream().filter(o -> Objects.equals(o.getJobId(), jobInfo.getId())).collect(Collectors.toList());
                                                    if (CollectionUtil.isNotEmpty(jobNodeLays)) {
                                                        for (JobNodeLayConfig jobNodeLay : jobNodeLays) {
                                                            if (null != jobNodeLay.getOutputTableId()) {
                                                                JobNodeInfo jobNodeInfo = jobNodes.stream().filter(o -> Objects.equals(o.getId(), jobNodeLay.getCurrentNodeId())).findAny().orElse(null);
                                                                if (null != jobNodeInfo) {
                                                                    //新增节点的配置信息
                                                                    List<JobNodeConf> allJobNodeConfs = copyAllDataDto.getAllJobNodeConfs();
                                                                    if (CollectionUtil.isNotEmpty(allJobNodeConfs)) {
                                                                        List<JobNodeConf> jobNodeConfings = allJobNodeConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), jobNodeLay.getCurrentNodeId())).collect(Collectors.toList());
                                                                        JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfings, 0);
                                                                        if (null != jobNodeConfig) {
                                                                            jobNodeInfo.setJobNodeConfig(jobNodeConfig);
                                                                        }
                                                                        List<JobNodeLayConfigDto> list = PojoUtils.listConvert(JobNodeLayConfigDto.class, Arrays.asList(jobNodeLay));
                                                                        jobNodeInfo.setJobNodeLayConfigDtoList(list);
                                                                        jobNodeInfo.setProcId(workMenu.getProcId());
                                                                        jobNodeInfo.setIsImport(1);
                                                                        try {
                                                                            jobNodeInfoService.saveJobNodeConfig(jobNodeInfo);
                                                                        } catch (Exception e) {
                                                                            log.error("生成节点配置信息异常！error:{}", e.getMessage());
                                                                            throw new RRException(e.getMessage());
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        List<JobNodeConf> allJobMenusConfs = copyAllDataDto.getAllJobMenusConfs();
                                        if (CollectionUtil.isNotEmpty(allJobMenusConfs)) {
                                            List<JobNodeConf> jobNodeConfs = allJobMenusConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), workMenu.getId().intValue())).collect(Collectors.toList());
                                            if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
                                                JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfs, 1);
                                                if (null != jobNodeConfig) {
                                                    jobLinkAndJobNodeDto.setJobNodeConfig(jobNodeConfig);
                                                }
                                            }
                                        }
                                        jobLinkAndJobNodeDto.setIsImport(1);
                                        iWorkMenuService.updateWorkJob(jobLinkAndJobNodeDto);
                                    }
                                }
                                //恢复对应的报警规则关联表数据
                                List<AlarmObject> alarmObjects = copyAllDataDto.getAlarmObjects();
                                if (CollectionUtil.isNotEmpty(alarmObjects)) {
                                    List<AlarmObject> collect = alarmObjects.stream().filter(o -> Objects.equals(o.getObjectId(), workMenuJobRel.getWorkMenuId().intValue())).collect(Collectors.toList());
                                    if (CollectionUtil.isNotEmpty(collect)) {
                                        alarmObjectService.saveOrUpdateBatch(collect);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            log.error("生成工作流:【" + workMenu.getName() + "】异常！error:{}", e.getMessage());
                            throw new RRException("生成工作流:【" + workMenu.getName() + "】异常！error:" + e.getMessage());
                        }
                    }
                }
            }
        }
    }

    private void updateRealWorkFlowJobs
            (List<UploadVersionWorkflowResultLog> filtWorkflows, List<RealTimeTaskMenu> rootAllWorkMenus, CopyAllDataDto
                    copyAllDataDto) {
        if (CollectionUtil.isNotEmpty(filtWorkflows)) {
            //先删除新建的，再还原
            List<UploadVersionWorkflowResultLog> temps = new ArrayList<>();
            for (UploadVersionWorkflowResultLog filtWorkflow : filtWorkflows) {
                temps.clear();
                temps.add(filtWorkflow);
                deleteAddRealWorkflows(filtWorkflows);
                RealTimeTaskMenu workMenu = rootAllWorkMenus.stream().filter(o -> Objects.equals(o.getId(), filtWorkflow.getExitWorkflowId())).findAny().orElse(null);
                if (null != workMenu) {
                    // 生成对应的job和jobNode
                    List<RealTimeTask> allRealTimeTask = copyAllDataDto.getAllRealTimeTask();
                    List<FlinkTaskNode> allFlinkTaskNode = copyAllDataDto.getAllFlinkTaskNode();
                    List<FlinkNodeUnion> allFlinkNodeUnion = copyAllDataDto.getAllFlinkNodeUnion();
                    List<FlinkNodeField> allFlinkNodeField = copyAllDataDto.getAllFlinkNodeField();
                    List<BdpRealTaskAlarmObject> alarmObjects = copyAllDataDto.getTaskAlarmObjects();
                    if (CollectionUtil.isNotEmpty(allRealTimeTask)) {
                        try {
                            RealTimeTask realTimeTask = allRealTimeTask.stream().filter(o -> Objects.equals(o.getMenuId(), workMenu.getId())).findAny().orElse(null);
                            if (realTimeTask != null) {
                                realTimeTaskMapper.insert(realTimeTask);
                            }
                            List<FlinkTaskNode> nodeList = allFlinkTaskNode.stream().filter(i -> i.getTaskId().equals(workMenu.getId())).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(nodeList)) {
                                List<Integer> oldNodeIds = nodeList.stream().map(i -> i.getId()).collect(Collectors.toList());
                                List<FlinkNodeUnion> unions = allFlinkNodeUnion.stream().filter(i -> i.getTaskId().equals(workMenu.getId())).collect(Collectors.toList());
                                List<FlinkNodeField> fields = allFlinkNodeField.stream().filter(i -> oldNodeIds.contains(i.getNodeId())).collect(Collectors.toList());
                                for (FlinkTaskNode flinkTaskNode : nodeList) {
                                    Integer oldId = flinkTaskNode.getId();
                                    flinkTaskNodeMapper.insertOrUpdateSelective(flinkTaskNode);
                                    Integer newId = flinkTaskNode.getId();
                                    if (CollectionUtil.isNotEmpty(unions)) {
                                        for (FlinkNodeUnion flinkNodeUnion : unions) {
                                            if (flinkNodeUnion.getNodeFrom().equals(oldId)) {
                                                flinkNodeUnion.setNodeFrom(newId);
                                            }
                                            if (flinkNodeUnion.getNodeTo().equals(oldId)) {
                                                flinkNodeUnion.setNodeTo(newId);
                                            }
                                        }
                                    }
                                    if (CollectionUtil.isNotEmpty(fields)) {
                                        for (FlinkNodeField flinkNodeField : fields) {
                                            if (flinkNodeField.getNodeId().equals(oldId)) {
                                                flinkNodeField.setNodeId(newId);
                                            }
                                        }
                                    }
                                }
                                if (CollectionUtil.isNotEmpty(fields)) {
                                    flinkNodeFieldMapper.batchInsert(fields);
                                }
                                if (CollectionUtil.isNotEmpty(unions)) {
                                    flinkNodeUnionMapper.batchInsert(unions);
                                }
                            }
                            List<BdpRealTaskAlarmObject> alarmObjectList = alarmObjects.stream().filter(i -> i.getObjectId().equals(workMenu.getId())).collect(Collectors.toList());
                            if (CollectionUtil.isNotEmpty(alarmObjectList)) {
                                realTaskAlarmObjectMapper.batchInsert(alarmObjectList);
                            }
                        } catch (Exception e) {
                            log.error("生成实时任务:【" + workMenu.getName() + "】异常！error:{}", e.getMessage());
                            throw new RRException("生成实时任务:【" + workMenu.getName() + "】异常！error:" + e.getMessage());
                        }
                    }
                }
            }
        }
    }

    private void deleteAddWorkflows(List<UploadVersionWorkflowResultLog> addWorkFlowJobs) {
        if (CollectionUtil.isEmpty(addWorkFlowJobs)) {
            return;
        }
        for (UploadVersionWorkflowResultLog addWorkFlowJob : addWorkFlowJobs) {
            if (!Objects.equals(null, addWorkFlowJob.getNewWorkflowDataId()) && !Objects.equals(0L, addWorkFlowJob.getNewWorkflowDataId())) {
                WorkMenu workMenu = workMenuMapper.selectById(addWorkFlowJob.getNewWorkflowDataId());
                if (null != workMenu) { //防止重复回滚
                    //删除对应的配置
                    delJob(workMenu);
                }
            }
        }
    }

    private void deleteAddRealWorkflows(List<UploadVersionWorkflowResultLog> addWorkFlowJobs) {
        if (CollectionUtil.isEmpty(addWorkFlowJobs)) {
            return;
        }
        for (UploadVersionWorkflowResultLog addWorkFlowJob : addWorkFlowJobs) {
            if (!Objects.equals(null, addWorkFlowJob.getNewWorkflowDataId()) && !Objects.equals(0L, addWorkFlowJob.getNewWorkflowDataId())) {
                RealTimeTaskMenu workMenu = realTimeTaskMenuMapper.selectById(addWorkFlowJob.getNewWorkflowDataId());
                if (null != workMenu) { //防止重复回滚
                    //删除对应的配置
                    delRealJob(workMenu);
                }
            }
        }
    }

    private void delJob(WorkMenu workMenu) {
        List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().
                eq("job_node_id", workMenu.getId()).eq("job_type", 1));
        if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
            jobNodeConfMapper.deleteBatchIds(jobNodeConfs.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
        }
        workMenuMapper.deleteById(workMenu.getId());
        jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("menu_id", workMenu.getId()).eq("linke_type", 0));
        WorkMenuJobRel workMenuJobRel = workMenuJobRelMapper.selectOne(new QueryWrapper<WorkMenuJobRel>()
                .eq("work_menu_id", workMenu.getId()).eq("work_type", 1));
        workMenuJobRelMapper.delete(new QueryWrapper<WorkMenuJobRel>().eq("work_menu_id", workMenu.getId()));
        if (null != workMenuJobRel) {
            jobInfoMapper.deleteById(workMenuJobRel.getWorkFlowId());
            List<JobNodeInfo> jobNodeInfos = jobNodeInfoMapper.selectList(new QueryWrapper<JobNodeInfo>().eq("job_id", workMenuJobRel.getWorkFlowId()));
            if (CollectionUtil.isNotEmpty(jobNodeInfos)) {
                for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
                    //删除对应的配置
                    List<JobNodeConf> jobNodeConfs1 = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().
                            eq("job_node_id", jobNodeInfo.getId()).eq("job_type", 0));
                    if (CollectionUtil.isNotEmpty(jobNodeConfs1)) {
                        jobNodeConfMapper.deleteBatchIds(jobNodeConfs1.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
                    }
                    //删除对应的shell的配置
                    bussessConfigMapper.delete(new QueryWrapper<BussessConfigEntity>().eq("bussess_type", 1).eq("bussess_id", jobNodeInfo.getId()));
                }
                jobNodeInfoMapper.deleteBatchIds(jobNodeInfos.stream().map(JobNodeInfo::getId).collect(Collectors.toList()));
            }
            //删除hdfs上的文件
            String baseDst = "workflow-app/" + WorkFlowType.WORKFLOW.getCode() + "/" + workMenu.getProcId() + "/";
            try {
                jobNodeInfoService.deleteShell(baseDst);
            } catch (IOException e) {
                log.error("删除hfds工作流脚本异常！error:{}", e.getMessage());
            }
        }
    }

    private void delRealJob(RealTimeTaskMenu workMenu) {
        List<FlinkNodeUnion> flinkNodeUnions = flinkNodeUnionMapper.selectList(new QueryWrapper<FlinkNodeUnion>().eq("task_id", workMenu.getId()));
        if (CollectionUtil.isNotEmpty(flinkNodeUnions)) {
            flinkNodeUnionMapper.delete(new QueryWrapper<FlinkNodeUnion>().eq("task_id", workMenu.getId()));
        }
        //删除实时任务菜单
        realTimeTaskMenuMapper.deleteById(workMenu.getId());
        //删除实时任务
        realTimeTaskMapper.delete(new QueryWrapper<RealTimeTask>().eq("menu_id", workMenu.getId()));
        List<FlinkTaskNode> nodes = flinkTaskNodeMapper.selectList(new QueryWrapper<FlinkTaskNode>().eq("task_id", workMenu.getId()));
        if (CollectionUtil.isNotEmpty(nodes)) {
            flinkTaskNodeMapper.delete(new QueryWrapper<FlinkTaskNode>().eq("task_id", workMenu.getId()));
            List<Integer> nodeIds = nodes.stream().map(i -> i.getId()).collect(Collectors.toList());
            List<FlinkNodeField> flinkNodeFields = flinkNodeFieldMapper.selectList(new QueryWrapper<FlinkNodeField>().in("node_id", nodeIds));
            if (CollectionUtil.isNotEmpty(flinkNodeFields)) {
                flinkNodeFieldMapper.delete(new QueryWrapper<FlinkNodeField>().in("node_id", nodeIds));
            }
        }
    }


    private void deleteAddWorkflowLays(List<UploadVersionWorkflowResultLog> addWorkFlowLays) {
        if (CollectionUtil.isEmpty(addWorkFlowLays)) {
            return;
        }
        //删除工作流依赖
        for (UploadVersionWorkflowResultLog uploadVersionWorkflowResultLog : addWorkFlowLays) {
            if (!Objects.equals(null, uploadVersionWorkflowResultLog.getNewWorkflowDataId()) && !Objects.equals(0L, uploadVersionWorkflowResultLog.getNewWorkflowDataId())) {
                WorkFlowDep workFlowDep = workFlowDepMapper.selectOne(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", uploadVersionWorkflowResultLog.getNewWorkflowDataId()));
                if (null != workFlowDep) { //防止重复回滚
                    delworkflowlaysByMenuId(workFlowDep);
                }
            }
        }
    }

    private void delworkflowlaysByMenuId(WorkFlowDep workFlowDep) {
        List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", workFlowDep.getWorkMenuId()).eq("job_type", 1));
        if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
            jobNodeConfMapper.deleteBatchIds(jobNodeConfs.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
        }
        jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("linke_type", 1).eq("menu_id", workFlowDep.getWorkMenuId()));
        workFlowDepMapper.delete(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", workFlowDep.getWorkMenuId()));
        workMenuJobRelMapper.delete(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 2).eq("work_menu_id", workFlowDep.getWorkMenuId()));
        workMenuMapper.deleteById(workFlowDep.getWorkMenuId());
        if (null != workFlowDep) {
            //删除hdfs上的文件
            String baseDst = "workflow-app/" + WorkFlowType.WORKFLOW_LAY.getCode() + "/" + workFlowDep.getProcId() + "/";
            try {
                jobNodeInfoService.deleteShell(baseDst);
            } catch (IOException e) {
                log.error("删除hfds工作流依赖脚本异常！error:{}", e.getMessage());
            }
        }

    }

    @Transactional(rollbackFor = Exception.class)
    public void rollbackConnectListsToOlders(CopyAllDataDto
                                                     copyAllDataDto, List<UploadVersionConnectResultLog> addConnects,
                                             List<UploadVersionConnectResultLog> updateConnects,
                                             Integer procId, Integer importChangeRole, String upZipEnv) {
        //新增的数据源连接直接删除
        deleteConnects(addConnects, procId);
        //修改的，则需要回滚
        rollbackConnects(copyAllDataDto, updateConnects, importChangeRole, procId, upZipEnv);
    }

    @Transactional(rollbackFor = Exception.class)
    public void rollbackTableListsToOlders(CopyAllDataDto
                                                   copyAllDataDto, List<UploadVersionTableResultLog> addTables,
                                           List<UploadVersionTableResultLog> updateTables,
                                           Integer procId, Integer importChangeRole, String upZipEnv) {
        //新增的数据仓库直接删除
        deleteTables(addTables, procId, importChangeRole);
        //修改的，则需要回滚
        rollbackTables(copyAllDataDto, updateTables, importChangeRole, procId, upZipEnv);
    }

    @Transactional(rollbackFor = Exception.class)
    public void rollbackRealTableListsToOlders(CopyAllDataDto
                                                       copyAllDataDto, List<UploadVersionTableResultLog> addTables,
                                               List<UploadVersionTableResultLog> updateTables,
                                               Integer procId, Integer importChangeRole, String upZipEnv) {
        //新增的实时表直接删除
        deleteRealTables(addTables, procId, importChangeRole);
        //修改的，则需要回滚
        rollbackRealTables(copyAllDataDto, updateTables, importChangeRole, procId, upZipEnv);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteTables(List<UploadVersionTableResultLog> addTables, Integer procId, Integer
            importChangeRole) {
        if (CollectionUtil.isEmpty(addTables)) {
            return;
        }
        for (UploadVersionTableResultLog addTable : addTables) {
            TableInfo tableInfo = tableInfoService.getById(addTable.getNewTableDataId());
            if (null != tableInfo) {
                List<TableFieldInfo> tableFieldInfos = deleteTables(procId, tableInfo, true, importChangeRole);
                if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    List<Long> ids = new ArrayList<>();
                    tableFieldInfos.forEach(o -> {
                        ids.add(Long.valueOf(o.getId()));
                    });
                    SysRoleDataPermissionExample param1 = new SysRoleDataPermissionExample();
                    param1.createCriteria()
                            .andDataTypeEqualTo(PermissionTypeEnum.STORE_FILED.getType())
                            .andDataIdIn(ids);
                    sysRoleDataPermissionMapper.deleteByExample(param1);
                }
            }

            SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
            param.createCriteria()
                    .andDataTypeEqualTo(PermissionTypeEnum.STORE.getType())
                    .andDataIdEqualTo(addTable.getNewTableDataId());
            sysRoleDataPermissionMapper.deleteByExample(param);

            //删除权限
            rangerDataService.deleteRangerPloicyByTableId(tableInfo.getId());
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteRealTables(List<UploadVersionTableResultLog> addTables, Integer procId, Integer
            importChangeRole) {
        if (CollectionUtil.isEmpty(addTables)) {
            return;
        }
        for (UploadVersionTableResultLog addTable : addTables) {
            BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectById(addTable.getNewTableDataId());
            if (null != tableInfo) {
                List<BdpRealTableField> tableFieldInfos = deleteRealTables(procId, tableInfo, true, importChangeRole);
                if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    List<Long> ids = new ArrayList<>();
                    tableFieldInfos.forEach(o -> {
                        ids.add(Long.valueOf(o.getId()));
                    });
                    SysRoleDataPermissionExample param1 = new SysRoleDataPermissionExample();
                    param1.createCriteria()
                            .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE_FILED.getType())
                            .andDataIdIn(ids);
                    sysRoleDataPermissionMapper.deleteByExample(param1);
                }
            }

            SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
            param.createCriteria()
                    .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE.getType())
                    .andDataIdEqualTo(addTable.getNewTableDataId());
            sysRoleDataPermissionMapper.deleteByExample(param);

        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void rollbackTables(CopyAllDataDto
                                       copyAllDataDto, List<UploadVersionTableResultLog> updateTables, Integer importChangeRole, Integer
                                       procId, String upZipEnv) {

        if (CollectionUtil.isEmpty(updateTables)) {
            return;
        }
        if (null == copyAllDataDto) {
            return;
        }
        List<TableInfo> allTableInfoLists = copyAllDataDto.getAllTableInfoLists();
        if (CollectionUtil.isEmpty(allTableInfoLists)) {
            return;
        }
        List<TableFieldInfo> allTableFieldInfoLists = copyAllDataDto.getAllTableFieldInfoLists();
        List<ProcTable> allProcTables = copyAllDataDto.getAllProcTables();
        Set<Integer> procTableIds = null;
        if (CollectionUtil.isNotEmpty(allProcTables)) {
            procTableIds = allProcTables.stream().map(ProcTable::getTableId).collect(Collectors.toSet());
        }
        List<SysRoleDataPermission> allPermissions = copyAllDataDto.getAllPermissions();
        for (UploadVersionTableResultLog updateTable : updateTables) {
            //先删除，再回滚---kudu和hive一样（回滚的时候都是这样）
            TableInfo tableInfo = tableInfoService.getById(updateTable.getNewTableDataId());
            List<TableFieldInfo> newTableFieldInfos = null;
            if (null != tableInfo) {
                newTableFieldInfos = deleteTables(procId, tableInfo, false, importChangeRole);
                //权限
                if (CollectionUtil.isNotEmpty(newTableFieldInfos)) {
                    if (null != importChangeRole) {
                        List<Long> ids = new ArrayList<>();
                        newTableFieldInfos.forEach(o -> {
                            ids.add(Long.valueOf(o.getId()));
                        });
                        SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                        param.createCriteria()
                                .andDataTypeEqualTo(PermissionTypeEnum.STORE_FILED.getType())
                                .andDataIdIn(ids)
                                .andRoleIdEqualTo(Long.valueOf(importChangeRole));
                        sysRoleDataPermissionMapper.deleteByExample(param);
                    }
                }
            }
            TableInfo olderTableInfo = allTableInfoLists.stream().filter(o -> Objects.equals(o.getId(), updateTable.getExitTableId().intValue())).findAny().orElse(null);
            List<TableFieldInfo> tableFieldInfos = null;
            if (null != olderTableInfo) {
                if (CollectionUtil.isNotEmpty(allTableFieldInfoLists)) {
                    tableFieldInfos = allTableFieldInfoLists.stream().filter(o -> Objects.equals(o.getTableId(), olderTableInfo.getId())).collect(Collectors.toList());
                }
                insertOrUpdateTableRollbackById(olderTableInfo, tableFieldInfos);
            }
            //重新配置字段权限
            if (null != importChangeRole) {
                if (CollectionUtil.isNotEmpty(allPermissions) && CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    List<Integer> ids = tableFieldInfos.stream().map(TableFieldInfo::getId).collect(Collectors.toList());
                    //字段权限
                    List<SysRoleDataPermission> sysRoleDataPermissions = allPermissions.stream().filter(o -> (ids.contains(o.getDataId())
                            && Objects.equals(o.getRoleId(), Long.valueOf(importChangeRole))
                            && Objects.equals(o.getDataType(), PermissionTypeEnum.STORE_FILED.getType()))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(sysRoleDataPermissions)) {
                        //先删除，再新增
                        sysRoleDataPermissionMapper.deleteBatchIds(sysRoleDataPermissions.stream().map(SysRoleDataPermission::getId).collect(Collectors.toList()));
                        sysRoleDataPermissionMapper.batchInsert(sysRoleDataPermissions);
                    }
                }
            }
            //如果没有关联，则把之前关联的删掉
            if (CollectionUtil.isEmpty(procTableIds) || !procTableIds.contains(updateTable.getExitTableId().intValue())) {
                procTableMapper.delete(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", updateTable.getExitTableId()));
            }
            if (null != importChangeRole) {
                //先删除权限，再回滚之前的权限
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.STORE.getType())
                        .andDataIdEqualTo(updateTable.getNewTableDataId())
                        .andRoleIdEqualTo(Long.valueOf(importChangeRole));
                sysRoleDataPermissionMapper.deleteByExample(param);

                if (CollectionUtil.isNotEmpty(allPermissions)) {
                    //表权限
                    SysRoleDataPermission sysRoleDataPermission = allPermissions.stream().filter(o -> (Objects.equals(o.getDataId(), updateTable.getExitTableId().intValue())
                            && Objects.equals(o.getRoleId(), Long.valueOf(importChangeRole))
                            && Objects.equals(o.getDataType(), PermissionTypeEnum.STORE.getType()))).findAny().orElse(null);
                    if (null != sysRoleDataPermission) {
                        sysRoleDataPermissionMapper.insertOrUpdateSelective(sysRoleDataPermission);
                        //ranger生成表权限
                    }
                }
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void rollbackRealTables(CopyAllDataDto
                                           copyAllDataDto, List<UploadVersionTableResultLog> updateTables, Integer importChangeRole, Integer
                                           procId, String upZipEnv) {

        if (CollectionUtil.isEmpty(updateTables)) {
            return;
        }
        if (null == copyAllDataDto) {
            return;
        }
        List<BdpRealTableInfo> allTableInfoLists = copyAllDataDto.getAllRealTableInfoLists();
        if (CollectionUtil.isEmpty(allTableInfoLists)) {
            return;
        }
        List<BdpRealTableField> allTableFieldInfoLists = copyAllDataDto.getAllRealTableFieldInfoLists();
        List<ProcTable> allProcTables = copyAllDataDto.getAllProcTables();
        Set<Integer> procTableIds = null;
        if (CollectionUtil.isNotEmpty(allProcTables)) {
            procTableIds = allProcTables.stream().filter(i -> i.getTableType() == 2).map(ProcTable::getTableId).collect(Collectors.toSet());
        }
        List<SysRoleDataPermission> allPermissions = copyAllDataDto.getAllPermissions();
        for (UploadVersionTableResultLog updateTable : updateTables) {
            BdpRealTableInfo tableInfo = bdpRealTableInfoMapper.selectById(updateTable.getNewTableDataId());
            List<BdpRealTableField> newTableFieldInfos = null;
            if (null != tableInfo) {
                newTableFieldInfos = deleteRealTables(procId, tableInfo, false, importChangeRole);
                //权限
                if (CollectionUtil.isNotEmpty(newTableFieldInfos)) {
                    if (null != importChangeRole) {
                        List<Long> ids = new ArrayList<>();
                        newTableFieldInfos.forEach(o -> {
                            ids.add(Long.valueOf(o.getId()));
                        });
                        SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                        param.createCriteria()
                                .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE_FILED.getType())
                                .andDataIdIn(ids)
                                .andRoleIdEqualTo(Long.valueOf(importChangeRole));
                        sysRoleDataPermissionMapper.deleteByExample(param);
                    }
                }
            }
            BdpRealTableInfo olderTableInfo = allTableInfoLists.stream().filter(o -> Objects.equals(o.getId(), updateTable.getExitTableId().intValue())).findAny().orElse(null);
            List<BdpRealTableField> tableFieldInfos = null;
            if (null != olderTableInfo) {
                if (CollectionUtil.isNotEmpty(allTableFieldInfoLists)) {
                    tableFieldInfos = allTableFieldInfoLists.stream().filter(o -> Objects.equals(o.getTableId(), olderTableInfo.getId())).collect(Collectors.toList());
                }
                insertOrUpdateRealTableRollbackById(olderTableInfo, tableFieldInfos);
            }
            //重新配置字段权限
            if (null != importChangeRole) {
                if (CollectionUtil.isNotEmpty(allPermissions) && CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    List<Integer> ids = tableFieldInfos.stream().map(BdpRealTableField::getId).collect(Collectors.toList());
                    //字段权限
                    List<SysRoleDataPermission> sysRoleDataPermissions = allPermissions.stream().filter(o -> (ids.contains(o.getDataId())
                            && Objects.equals(o.getRoleId(), Long.valueOf(importChangeRole))
                            && Objects.equals(o.getDataType(), PermissionTypeEnum.REAL_TABLE_FILED.getType()))).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(sysRoleDataPermissions)) {
                        //先删除，再新增
                        sysRoleDataPermissionMapper.deleteBatchIds(sysRoleDataPermissions.stream().map(SysRoleDataPermission::getId).collect(Collectors.toList()));
                        sysRoleDataPermissionMapper.batchInsert(sysRoleDataPermissions);
                    }
                }
            }
            //如果没有关联，则把之前关联的删掉
            if (CollectionUtil.isEmpty(procTableIds) || !procTableIds.contains(updateTable.getExitTableId().intValue())) {
                procTableMapper.delete(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", updateTable.getExitTableId()).eq("proc_id", procId).eq("table_type", 2));
            }
            if (null != importChangeRole) {
                //先删除权限，再回滚之前的权限
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE.getType())
                        .andDataIdEqualTo(updateTable.getNewTableDataId())
                        .andRoleIdEqualTo(Long.valueOf(importChangeRole));
                sysRoleDataPermissionMapper.deleteByExample(param);

                if (CollectionUtil.isNotEmpty(allPermissions)) {
                    //表权限
                    SysRoleDataPermission sysRoleDataPermission = allPermissions.stream().filter(o -> (Objects.equals(o.getDataId(), updateTable.getExitTableId().intValue())
                            && Objects.equals(o.getRoleId(), Long.valueOf(importChangeRole))
                            && Objects.equals(o.getDataType(), PermissionTypeEnum.REAL_TABLE.getType()))).findAny().orElse(null);
                    if (null != sysRoleDataPermission) {
                        sysRoleDataPermissionMapper.insertOrUpdateSelective(sysRoleDataPermission);
                        //ranger生成表权限
                    }
                }
            }
        }
    }


    @Transactional(rollbackFor = Exception.class)
    public void rollbackConnects(CopyAllDataDto
                                         copyAllDataDto, List<UploadVersionConnectResultLog> updateConnects, Integer importChangeRole, Integer
                                         procId, String upZipEnv) {

        if (CollectionUtil.isEmpty(updateConnects)) {
            return;
        }
        if (null == copyAllDataDto) {
            return;
        }
        List<ConfConnect> allConfConnects = copyAllDataDto.getAllConnectLists();
        if (CollectionUtil.isEmpty(allConfConnects)) {
            return;
        }
        List<ConnectFieldInfo> allConnectFields = copyAllDataDto.getAllConnectFieldLists();
        List<SapConnectField> allSapConnectFieldLists = copyAllDataDto.getAllSapConnectFieldLists();
        List<SysRoleDataPermission> allPermissions = copyAllDataDto.getAllPermissions();
        List<ProcConnect> allProcConnects = copyAllDataDto.getAllProcConnects();
        Set<Integer> procConnectIds = null;
        if (CollectionUtil.isNotEmpty(allProcConnects)) {
            procConnectIds = allProcConnects.stream().map(ProcConnect::getConnectId).collect(Collectors.toSet());
        }
        for (UploadVersionConnectResultLog updateConnect : updateConnects) {
            //先删除，再回滚
            deleteConnects(procId, updateConnect.getNewConnectDataId().intValue());

            ConfConnect confConnect = allConfConnects.stream().filter(o -> Objects.equals(o.getId(), updateConnect.getExitConnectId().intValue())).findAny().orElse(null);
            List<ConnectFieldInfo> connectFieldInfos = null;
            List<SapConnectField> sapConnectFields = null;
            if (null != confConnect) {
                if (CollectionUtil.isNotEmpty(allConnectFields)) {
                    connectFieldInfos = allConnectFields.stream().filter(o -> Objects.equals(o.getConnectId(), confConnect.getId())).collect(Collectors.toList());
                }
                if (CollectionUtil.isNotEmpty(allSapConnectFieldLists)) {
                    sapConnectFields = allSapConnectFieldLists.stream().filter(o -> Objects.equals(o.getConnectId(), confConnect.getId())).collect(Collectors.toList());
                }
                insertOrUpdateConnectRollbackById(confConnect, connectFieldInfos, sapConnectFields);
            }
            //如果没有关联，则把之前关联的删掉
            if (CollectionUtil.isEmpty(procConnectIds) || !procConnectIds.contains(updateConnect.getExitConnectId().intValue())) {
                procConnectMapper.delete(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", updateConnect.getNewConnectDataId()));
            }
            if (null != importChangeRole) {
                //先删除权限，再回滚之前的权限
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.RESOURCE.getType())
                        .andDataIdEqualTo(updateConnect.getNewConnectDataId())
                        .andRoleIdEqualTo(Long.valueOf(importChangeRole));
                sysRoleDataPermissionMapper.deleteByExample(param);

                if (CollectionUtil.isNotEmpty(allPermissions)) {
                    SysRoleDataPermission sysRoleDataPermission = allPermissions.stream().filter(o -> (Objects.equals(o.getDataId(), updateConnect.getExitConnectId().intValue())
                            && Objects.equals(o.getRoleId(), Long.valueOf(importChangeRole))
                            && Objects.equals(o.getDataType(), PermissionTypeEnum.RESOURCE.getType()))).findAny().orElse(null);
                    if (null != sysRoleDataPermission) {
                        sysRoleDataPermissionMapper.insertOrUpdateSelective(sysRoleDataPermission);
                    }
                }
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertOrUpdateConnectRollbackById(ConfConnect
                                                          confConnect, List<ConnectFieldInfo> connectFieldInfos, List<SapConnectField> sapConnectFields) {
        if (null != confConnect) {
            confConnectMapper.insertAndId(confConnect);
        }
        if (CollectionUtil.isNotEmpty(connectFieldInfos)) {
            connectFieldInfoService.saveBatch(connectFieldInfos);
        }
        if (CollectionUtil.isNotEmpty(sapConnectFields)) {
            for (SapConnectField sapConnectField : sapConnectFields) {
                sapConnectFieldMapper.insert(sapConnectField);
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertOrUpdateTableRollbackById(TableInfo
                                                        olderTableInfo, List<TableFieldInfo> tableFieldInfos) {

        if (null == olderTableInfo) {
            return;
        }
        olderTableInfo.setTableFieldInfos(tableFieldInfos);
        //创建hive仓库表数据
        try {
            long startTime = new Date().getTime();
            R hiveTableMap = HiveTableDdl.createHiveTable(olderTableInfo, hiveConfig);
            if (null != hiveTableMap && hiveTableMap.get("code").equals(0)) {
                tableInfoMapper.insertAndId(olderTableInfo);
                if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
                    //批量生成字段数据
                    tableFieldInfoService.saveBatch(tableFieldInfos);
                }

                if (Objects.equals(olderTableInfo.getStoreEngine(), StorageEngineEnum.HIVE.getCode())) {
                    //刷新对应的数据
                    //修改表数据后刷新表结构重新识别旧的数据
                    HiveTableUtil hiveTableUtil = new HiveTableUtil(hiveConfig.getHiveserverurl(), olderTableInfo.getDbName(), "hdfs", "hdfs");
                    try {
                        hiveTableUtil.repairTable(olderTableInfo.getTableName());
                        hiveTableUtil.close();
                    } catch (Exception e) {
                        log.error("repair数据仓库：【{}.{}】异常", olderTableInfo.getDbName(), olderTableInfo.getTableName());
                        hiveTableUtil.close();
                    }
                }

                //元数据注册表
                //注册数据表数据
                Date curr = new Date();
                TableRegisterEntity registerEntity = new TableRegisterEntity();
                registerEntity.setTableInfoId(olderTableInfo.getId());
                registerEntity.setBatchNum(curr.getTime());
                registerEntity.setRegisterType(TableRegisterTypeEnum.OFFLINE_UPDATE.getCode());
                long cost = curr.getTime() - startTime;
                registerEntity.setCost(cost);
                registerEntity.setRunTime(curr);
                registerEntity.setRunUser(olderTableInfo.getCreatePer().longValue());
                tableRegisterService.save(registerEntity);

            } else {
                String msg = "";
                if (null != hiveTableMap) {
                    msg = hiveTableMap.get("msg") == null ? "" : hiveTableMap.get("msg").toString();
                }
                throw new RRException("回滚数据仓库：【" + olderTableInfo.getDbName() + "." + olderTableInfo.getTableName() + "】异常!" + msg);
            }
        } catch (Exception e) {
            log.error("生成数据仓库：【{}.{}】异常", olderTableInfo.getDbName(), olderTableInfo.getTableName());
            throw new RRException("生成数据仓库：【" + olderTableInfo.getDbName() + "." + olderTableInfo.getTableName() + "】异常");
        }

    }

    @Transactional(rollbackFor = Exception.class)
    public void insertOrUpdateRealTableRollbackById(BdpRealTableInfo
                                                            olderTableInfo, List<BdpRealTableField> tableFieldInfos) {

        if (null == olderTableInfo) {
            return;
        }
        //创建实时表
        try {
            long startTime = new Date().getTime();
            bdpRealTableInfoMapper.insertAndId(olderTableInfo);
            //生成对应的字段
            Map<String, List<BdpRealTableField>> dataList = null;
            if (CollectionUtil.isNotEmpty(tableFieldInfos)) {
                List<BdpRealTableField> listsNoIds = new ArrayList<>();
                for (BdpRealTableField tableFieldInfo : tableFieldInfos) {
                    tableFieldInfo.setTableId(olderTableInfo.getId());
                    tableFieldInfo.setCreateUser(ShiroUtils.getUserId());
                    listsNoIds.add(tableFieldInfo);
                }
                if (CollectionUtil.isNotEmpty(listsNoIds)) {
                    realTableFieldMapper.batchInsert(listsNoIds);
                }
            }
            //元数据注册表
            //注册数据表数据
            Date curr = new Date();
            TableRegisterEntity registerEntity = new TableRegisterEntity();
            registerEntity.setTableInfoId(olderTableInfo.getId());
            registerEntity.setBatchNum(curr.getTime());
            registerEntity.setRegisterType(TableRegisterTypeEnum.ONLINE_UPDATE.getCode());
            long cost = curr.getTime() - startTime;
            registerEntity.setCost(cost);
            registerEntity.setRunTime(curr);
            registerEntity.setRunUser(olderTableInfo.getCreateUser().longValue());
            tableRegisterService.save(registerEntity);
        } catch (Exception e) {
            log.error("生成实时表：【{}.{}】异常", olderTableInfo.getDbName(), olderTableInfo.getTableName());
            throw new RRException("生成实时表：【" + olderTableInfo.getDbName() + "." + olderTableInfo.getTableName() + "】异常");
        }

    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteConnects(List<UploadVersionConnectResultLog> addConnects, Integer procId) {
        if (CollectionUtil.isNotEmpty(addConnects)) {
            for (UploadVersionConnectResultLog addConnect : addConnects) {

                deleteConnects(procId, addConnect.getNewConnectDataId().intValue());
                //删除授权数据
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.RESOURCE.getType())
                        .andDataIdEqualTo(addConnect.getNewConnectDataId());
                sysRoleDataPermissionMapper.deleteByExample(param);
            }
        }
    }

    private void stopWorkflowlays
            (List<UploadVersionWorkflowResultLog> needStops, List<String> errorList) {
        if (CollectionUtil.isNotEmpty(needStops)) {
            for (UploadVersionWorkflowResultLog needStop : needStops) {
                WorkFlowDep workFlowDep = workFlowDepMapper.selectById(needStop.getNewJobId());
                if (null != workFlowDep) { //防止重复回滚
                    if (Objects.equals(workFlowDep.getJobLayStatus(), 1)) {
                        WorkMenu workMenu = workMenuMapper.selectById(workFlowDep.getWorkMenuId());
                        String workLayName = null == workMenu ? "" : workMenu.getName();
                        try {
                            iWorkMenuService.closeWorkFlowJob(workFlowDep.getWorkMenuId());
                        } catch (Exception e) {
                            log.error("禁用工作流依赖【" + workLayName + "】异常！error:{}", e.getMessage());
                        }
                    }
                }
            }
        }
    }

    private void stopWorkflowJobs
            (List<UploadVersionWorkflowResultLog> needStops, List<String> errorList) {
        if (CollectionUtil.isNotEmpty(needStops)) {
            for (UploadVersionWorkflowResultLog needStop : needStops) {
                JobInfo jobInfo = jobInfoMapper.selectById(needStop.getNewJobId());
                if (null != jobInfo) { //防止重复回滚
                    killJob(jobInfo);
                }
            }
        }
    }

    private void killJob(JobInfo jobInfo) {
        List<WorkMenuJobRel> workMenuJobRels = workMenuJobRelMapper.selectList(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 1).eq("work_flow_id", jobInfo.getId()));
        if (CollectionUtil.isNotEmpty(workMenuJobRels)) {
            Set<Long> collect = workMenuJobRels.stream().map(WorkMenuJobRel::getWorkMenuId).collect(Collectors.toSet());
            if (CollectionUtil.isNotEmpty(collect)) {
                for (Long aLong : collect) {
                    try {
                        iWorkMenuService.stopWorkJob(aLong, Boolean.TRUE);
                    } catch (Exception e) {
                        log.error("暂停工作流【" + jobInfo.getName() + "】异常！error:{}", e.getMessage());
                    }
                }
            }
        }
    }

    /***
     * 所有表的数据信息
     *
     * @param procId
     * @param roleId
     * @return
     */
    private CopyAllDataDto listAllCopyData(Integer procId, Integer roleId) {
        CopyAllDataDto copyAllDataDto = new CopyAllDataDto();
        copyAllDataDto.setProcId(procId);

        List<SysRoleDataPermission> allPermissions = new ArrayList<>();
        //查询所有的数据源
        List<ConfConnect> allConfConnectList = confConnectMapper.selectList(new QueryWrapper<ConfConnect>());
        if (CollectionUtil.isNotEmpty(allConfConnectList)) {
            //所有的数据源
            copyAllDataDto.setAllConnectLists(allConfConnectList);
            //数据源连接相关
            List<ProcConnect> procConnects = procConnectMapper.selectList(new QueryWrapper<ProcConnect>().eq("proc_id", procId));
            if (CollectionUtil.isNotEmpty(procConnects)) {
                copyAllDataDto.setAllProcConnects(procConnects);
            }
            List<ConnectFieldInfo> connectFieldInfos = connectFieldInfoMapper.selectList(new QueryWrapper<ConnectFieldInfo>());
            if (CollectionUtil.isNotEmpty(connectFieldInfos)) {
                copyAllDataDto.setAllConnectFieldLists(connectFieldInfos);
            }
            List<SapConnectField> allSapConnectFields = sapConnectFieldMapper.selectList(new QueryWrapper<SapConnectField>());
            if (CollectionUtil.isNotEmpty(allSapConnectFields)) {
                copyAllDataDto.setAllSapConnectFieldLists(allSapConnectFields);
            }
            if (null != roleId) {
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.RESOURCE.getType())
                        .andRoleIdEqualTo(Long.valueOf(roleId));
                List<SysRoleDataPermission> sysRoleDataPermissions = sysRoleDataPermissionMapper.selectByExample(param);
                if (CollectionUtil.isNotEmpty(sysRoleDataPermissions)) {
                    allPermissions.addAll(sysRoleDataPermissions);
                }
            }
        }

        //数据仓库相关的表数据
        List<TableInfo> tableInfos = tableInfoMapper.selectList(new QueryWrapper<TableInfo>());
        if (CollectionUtil.isNotEmpty(tableInfos)) {
            copyAllDataDto.setAllTableInfoLists(tableInfos);
            List<ProcTable> procTables = procTableMapper.selectList(new QueryWrapper<ProcTable>().eq("proc_id", procId));
            if (CollectionUtil.isNotEmpty(procTables)) {
                copyAllDataDto.setAllProcTables(procTables);
            }
            List<TableFieldInfo> allTableFields = tableFieldInfoMapper.selectList(new QueryWrapper<TableFieldInfo>());
            if (CollectionUtil.isNotEmpty(allTableFields)) {
                copyAllDataDto.setAllTableFieldInfoLists(allTableFields);
            }
            if (null != roleId) {
                SysRoleDataPermissionExample param1 = new SysRoleDataPermissionExample();
                param1.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.STORE.getType())
                        .andRoleIdEqualTo(Long.valueOf(roleId));
                List<SysRoleDataPermission> sysRoleDataPermissions1 = sysRoleDataPermissionMapper.selectByExample(param1);
                if (CollectionUtil.isNotEmpty(sysRoleDataPermissions1)) {
                    allPermissions.addAll(sysRoleDataPermissions1);
                }
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.STORE_FILED.getType())
                        .andRoleIdEqualTo(Long.valueOf(roleId));
                List<SysRoleDataPermission> sysRoleDataPermissions = sysRoleDataPermissionMapper.selectByExample(param);
                if (CollectionUtil.isNotEmpty(sysRoleDataPermissions)) {
                    allPermissions.addAll(sysRoleDataPermissions);
                }
            }
        }

        //实时表数据
        List<BdpRealTableInfo> realTableInfos = bdpRealTableInfoMapper.selectList(new QueryWrapper<BdpRealTableInfo>());
        if (CollectionUtil.isNotEmpty(realTableInfos)) {
            copyAllDataDto.setAllRealTableInfoLists(realTableInfos);
            List<BdpRealTableField> allTableFields = realTableFieldMapper.selectList(new QueryWrapper<BdpRealTableField>());
            if (CollectionUtil.isNotEmpty(allTableFields)) {
                copyAllDataDto.setAllRealTableFieldInfoLists(allTableFields);
            }
            if (null != roleId) {
                SysRoleDataPermissionExample param1 = new SysRoleDataPermissionExample();
                param1.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE.getType())
                        .andRoleIdEqualTo(Long.valueOf(roleId));
                List<SysRoleDataPermission> sysRoleDataPermissions1 = sysRoleDataPermissionMapper.selectByExample(param1);
                if (CollectionUtil.isNotEmpty(sysRoleDataPermissions1)) {
                    allPermissions.addAll(sysRoleDataPermissions1);
                }
                SysRoleDataPermissionExample param = new SysRoleDataPermissionExample();
                param.createCriteria()
                        .andDataTypeEqualTo(PermissionTypeEnum.REAL_TABLE_FILED.getType())
                        .andRoleIdEqualTo(Long.valueOf(roleId));
                List<SysRoleDataPermission> sysRoleDataPermissions = sysRoleDataPermissionMapper.selectByExample(param);
                if (CollectionUtil.isNotEmpty(sysRoleDataPermissions)) {
                    allPermissions.addAll(sysRoleDataPermissions);
                }
            }
        }

        if (CollectionUtil.isNotEmpty(allPermissions)) {
            copyAllDataDto.setAllPermissions(allPermissions);
        }
        //udf相关的表数据
        List<BdpUdfJarInfo> bdpUdfJarInfos = bdpUdfJarInfoMapper.selectList(new QueryWrapper<BdpUdfJarInfo>().eq("proc_id", procId));
        if (CollectionUtil.isNotEmpty(bdpUdfJarInfos)) {
            copyAllDataDto.setAllUdfJarInfos(bdpUdfJarInfos);
            Set<Integer> udfJarIds = bdpUdfJarInfos.stream().map(BdpUdfJarInfo::getId).collect(Collectors.toSet());
            List<JobRunUdf> allJobRunUdfs = jobRunUdfMapper.selectByUdfJarIds(udfJarIds);
            if (CollectionUtil.isNotEmpty(allJobRunUdfs)) {
                copyAllDataDto.setAllJobRunUdfs(allJobRunUdfs);
            }
        }
        //菜单工作流相关表数据
        List<WorkMenu> allWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
        if (CollectionUtil.isNotEmpty(allWorkMenus)) {
            copyAllDataDto.setAllWorkMenus(allWorkMenus);
            Set<Long> workMenuIds = allWorkMenus.stream().map(WorkMenu::getId).collect(Collectors.toSet());
            List<WorkMenuJobRel> allWorkMenuJobRels = workMenuJobRelMapper.selectByWorkMenuIds(workMenuIds);
            if (CollectionUtil.isNotEmpty(allWorkMenuJobRels)) {
                copyAllDataDto.setAllWorkMenuJobRels(allWorkMenuJobRels);
                List<WorkMenuJobRel> jobRels = allWorkMenuJobRels.stream().filter(o -> Objects.equals(o.getWorkType(), 1)).collect(Collectors.toList());
                if (CollectionUtil.isNotEmpty(jobRels)) {
                    //对应的报警规则列表
                    Set<Long> olderWorkMenuIds = jobRels.stream().map(WorkMenuJobRel::getWorkMenuId).collect(Collectors.toSet());
                    if (CollectionUtil.isNotEmpty(olderWorkMenuIds)) {
                        //查询到对应的规则
                        List<AlarmObject> restList = alarmObjectService.listWorkFlowByWorkMenuIds(olderWorkMenuIds, cn.getech.data.intelligence.common.utils.Constant.AlarmTypeEnum.TASK_ALARM.getCode());
                        if (CollectionUtil.isNotEmpty(restList)) {
                            copyAllDataDto.setAlarmObjects(restList);
                        }
                    }
                    Set<Long> jobIds = jobRels.stream().map(WorkMenuJobRel::getWorkFlowId).collect(Collectors.toSet());
                    if (CollectionUtil.isNotEmpty(jobIds)) {
                        List<JobInfo> allJobInfos = jobInfoMapper.selectListByJobIds(jobIds);
                        if (CollectionUtil.isNotEmpty(allJobInfos)) {
                            copyAllDataDto.setAllJobInfos(allJobInfos);
                            //查询其下的节点信息
                            List<JobNodeInfo> allJobNodeInfos = jobNodeInfoMapper.selectListByJobIds(jobIds);
                            if (CollectionUtil.isNotEmpty(allJobNodeInfos)) {
                                copyAllDataDto.setAllJobNodeInfos(allJobNodeInfos);
                                Set<Integer> jobNodeIds = allJobNodeInfos.stream().map(JobNodeInfo::getId).collect(Collectors.toSet());
                                List<JobNodeConf> allJobNodeConfs = jobNodeConfMapper.selectByJobNodeIds(jobNodeIds);
                                if (CollectionUtil.isNotEmpty(allJobNodeConfs)) {
                                    copyAllDataDto.setAllJobNodeConfs(allJobNodeConfs);
                                }
                            }
                            //路由配置
                            List<JobNodeLayConfig> allJobNodeLayConfigs = jobNodeLayConfigMapper.selectListByJobIds(jobIds);
                            if (CollectionUtil.isNotEmpty(allJobNodeLayConfigs)) {
                                copyAllDataDto.setAllJobNodeLayCongigs(allJobNodeLayConfigs);
                            }
                            //查询到关联的质量报警规则
                            String baseReqUrl = dataDevelopmentConfig.getDataManagerUrl() + "/bdp/dataManagerQualityRulesRel/listRuleRelsByIds?jobIds=" + jobIds.toString();
                            List<DataManagerQualityRulesRelDto> dataManagerQualityRulesRelDtos = iBdpVersionService.listRulesRelDtos(baseReqUrl);
                            if (CollectionUtil.isNotEmpty(dataManagerQualityRulesRelDtos)) {
                                copyAllDataDto.setDataManagerQualityRulesRelDtos(dataManagerQualityRulesRelDtos);
                            }
                        }
                    }
                }
            }
            List<JobLink> allJobLinks = jobLinkMapper.selectByMenuIds(workMenuIds);
            if (CollectionUtil.isNotEmpty(allJobLinks)) {
                copyAllDataDto.setAllJobLinks(allJobLinks);
            }
            List<JobNodeConf> allJobMenuConfs = jobNodeConfMapper.selectByWorkMenuIds(workMenuIds);
            if (CollectionUtil.isNotEmpty(allJobMenuConfs)) {
                copyAllDataDto.setAllJobMenusConfs(allJobMenuConfs);
            }
        }
        //实时任务相关数据
        List<RealTimeTaskMenu> allRealWorkMenus = realTimeTaskMenuMapper.selectList(new QueryWrapper<RealTimeTaskMenu>().eq("proc_id", procId).eq("state", 1));
        if (CollectionUtil.isNotEmpty(allRealWorkMenus)) {
            copyAllDataDto.setAllRealWorkMenus(allRealWorkMenus);
            Set<Integer> workMenuIds = allRealWorkMenus.stream().map(RealTimeTaskMenu::getId).collect(Collectors.toSet());
            List<RealTimeTask> allRealTimeTasks = realTimeTaskMapper.selectList(new QueryWrapper<RealTimeTask>().in("menu_id", workMenuIds));
            if (CollectionUtil.isNotEmpty(allRealTimeTasks)) {
                copyAllDataDto.setAllRealTimeTask(allRealTimeTasks);
            }
            List<FlinkTaskNode> allFlinkTaskNode = flinkTaskNodeMapper.selectList(new QueryWrapper<FlinkTaskNode>().in("task_id", workMenuIds));
            if (CollectionUtil.isNotEmpty(allFlinkTaskNode)) {
                copyAllDataDto.setAllFlinkTaskNode(allFlinkTaskNode);
                Set<Integer> nodeIds = allFlinkTaskNode.stream().map(FlinkTaskNode::getId).collect(Collectors.toSet());
                List<FlinkNodeField> allFlinkNodeField = flinkNodeFieldMapper.selectList(new QueryWrapper<FlinkNodeField>().in("node_id", nodeIds));
                if (CollectionUtil.isNotEmpty(allFlinkNodeField)) {
                    copyAllDataDto.setAllFlinkNodeField(allFlinkNodeField);
                }
            }
            List<FlinkNodeUnion> allFlinkNodeUnion = flinkNodeUnionMapper.selectList(new QueryWrapper<FlinkNodeUnion>().in("task_id", workMenuIds));
            if (CollectionUtil.isNotEmpty(allFlinkNodeUnion)) {
                copyAllDataDto.setAllFlinkNodeUnion(allFlinkNodeUnion);
            }
            List<BdpRealTaskAlarmObject> alarmObjects = realTaskAlarmObjectMapper.selectList(new QueryWrapper<BdpRealTaskAlarmObject>().in("object_id", workMenuIds));
            if (CollectionUtil.isNotEmpty(alarmObjects)) {
                copyAllDataDto.setTaskAlarmObjects(alarmObjects);
            }
        }
        List<WorkFlowDep> workFlowDeps = workFlowDepMapper.selectList(new QueryWrapper<WorkFlowDep>().eq("proc_id", procId));
        if (CollectionUtil.isNotEmpty(workFlowDeps)) {
            copyAllDataDto.setAllWorkFlowDeps(workFlowDeps);
        }

        return copyAllDataDto;
    }

    private VersionZipDto getZipData(Integer procId, String versionUUid) {
        List<FileModelDto> unzipList = null;
        HdfsUtil hdfsUtil = null;
        try {
            //将解析file文件上传到hdfs保存起来
            hdfsUtil = new HdfsUtil(bdpJobConfig);
            String uploadPath = String.format("%s/%s", bdpJobConfig.getVersion(), procId);
            unzipList = hdfsUtil.readFile(uploadPath, Arrays.asList(versionUUid + ".json"));
            hdfsUtil.close();
        } catch (Exception e) {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
            log.error("读取上传的版本包文件异常！error:{}", e.getMessage());
            throw new RRException("读取上传的版本包文件异常！");
        } finally {
            if (null != hdfsUtil) {
                hdfsUtil.close();
            }
        }
        if (CollectionUtil.isEmpty(unzipList)) {
            throw new RRException("读取上传的版本包文件为空！");
        }
        //解析文件，并且判断是否满足条件
        VersionZipDto versionZipDto = null;
        if (CollectionUtil.isNotEmpty(unzipList)) {
            versionZipDto = changeZip(unzipList, Boolean.TRUE);
        }
        return versionZipDto;
    }


    private Long deleteAllInfoByWorkMenuLayId(Long workMenuFlowLayId) {
        Long workDepId = null;
        WorkMenu workMenu = workMenuMapper.selectById(workMenuFlowLayId);
        if (null != workMenu) {
            workMenuMapper.deleteById(workMenuFlowLayId);
        }
        WorkFlowDep workFlowDep = workFlowDepMapper.selectOne(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", workMenuFlowLayId));
        if (null != workFlowDep) {
            workDepId = workFlowDep.getId();
            workFlowDepMapper.delete(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", workMenuFlowLayId));
        }
        List<WorkMenuJobRel> workMenuJobRels1 = workMenuJobRelMapper.selectList(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 2).eq("work_menu_id", workMenuFlowLayId));
        if (CollectionUtil.isNotEmpty(workMenuJobRels1)) {
            workMenuJobRelMapper.delete(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 2).eq("work_menu_id", workMenuFlowLayId));
        }
        List<JobLink> jobLinks = jobLinkMapper.selectList(new QueryWrapper<JobLink>().eq("menu_id", workMenuFlowLayId).eq("linke_type", 1));
        if (CollectionUtil.isNotEmpty(jobLinks)) {
            jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("menu_id", workMenuFlowLayId).eq("linke_type", 1));
        }
        List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuFlowLayId).eq("job_type", 1));
        if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
            jobNodeConfMapper.delete(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuFlowLayId).eq("job_type", 1));
        }
        return workDepId;
    }

    private Integer deleteAllInfoByWorkMenuId(Long
                                                      workMenuFlowId, List<JobNodeInfo> olderJobNodeInfos, WorkMenu
                                                      workMenuLay) {
        //查询到任务
        Integer jobId = null;
        WorkMenuJobRel workMenuJobRel = workMenuJobRelMapper.selectOne(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 1).eq("work_menu_id", workMenuFlowId));
        if (null != workMenuJobRel) {
            JobInfo jobInfo = jobInfoMapper.selectById(workMenuJobRel.getWorkFlowId());
            if (null != jobInfo) {
                jobId = jobInfo.getId();
                //查询到节点信息
                List<JobNodeInfo> jobNodeInfos = jobNodeInfoMapper.selectList(new QueryWrapper<JobNodeInfo>().eq("job_id", jobInfo.getId()));
                //先暂停作业流
                try {
                    iWorkMenuService.stopWorkJob(workMenuFlowId, Boolean.TRUE);
                } catch (Exception e) {
                    log.error("暂停任务异常！error:{}", e.getMessage());
                }

                //删除节点
                if (CollectionUtil.isNotEmpty(jobNodeInfos)) {
                    olderJobNodeInfos.addAll(olderJobNodeInfos);
                    List<Integer> jobNodeIds = jobNodeInfos.stream().map(JobNodeInfo::getId).collect(Collectors.toList());
                    for (Integer jobNodeId : jobNodeIds) {
                        jobNodeConfMapper.delete(new QueryWrapper<JobNodeConf>().eq("job_node_id", jobNodeId).eq("job_type", 0));
                        bussessConfigMapper.delete(new QueryWrapper<BussessConfigEntity>().eq("bussess_type", 1).eq("bussess_id", jobNodeId));
                    }
                    jobNodeInfoMapper.deleteBatchIds(jobNodeIds);
                }

                //删除任务
                jobInfoMapper.deleteById(jobInfo.getId());

                //删除路由配置信息
                jobNodeLayConfigMapper.delete(new QueryWrapper<JobNodeLayConfig>().eq("job_id", jobInfo.getId()));

                //查询这个节点是否有对应的作业流依赖引用
                if (null != jobInfo.getPosY() && null != jobInfo.getPosX()) {
                    List<WorkMenuJobRel> workMenuJobRels = workMenuJobRelMapper.selectList(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 2).eq("work_flow_id", jobId));
                    if (CollectionUtil.isNotEmpty(workMenuJobRels)) {
                        //查询到对应的依赖是否是启用（如果是启用，则需要先禁用，再改为启用）
                        WorkFlowDep workFlowDep = workFlowDepMapper.selectOne(new QueryWrapper<WorkFlowDep>().eq("work_menu_id", workMenuJobRels.get(0).getWorkMenuId()));
                        if (null != workFlowDep && Objects.equals(1, workFlowDep.getJobLayStatus())) {
                            workMenuLay.setId(workFlowDep.getWorkMenuId());
                        }
                    }
                }
            }
        }

        //删除菜单和菜单关联
        List<WorkMenuJobRel> workMenuJobRels = workMenuJobRelMapper.selectList(new QueryWrapper<WorkMenuJobRel>().eq("work_menu_id", workMenuFlowId).in("work_type", 0, 1));
        if (CollectionUtil.isNotEmpty(workMenuJobRels)) {
            workMenuJobRelMapper.delete(new QueryWrapper<WorkMenuJobRel>().eq("work_menu_id", workMenuFlowId).in("work_type", 0, 1));
        }
        WorkMenu workMenu = workMenuMapper.selectById(workMenuFlowId);
        if (null != workMenu) {
            workMenuMapper.deleteById(workMenuFlowId);
        }

        //删除连线信息
        List<JobLink> jobLinks = jobLinkMapper.selectList(new QueryWrapper<JobLink>().eq("menu_id", workMenuFlowId).eq("linke_type", 0));
        if (CollectionUtil.isNotEmpty(jobLinks)) {
            jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("menu_id", workMenuFlowId).eq("linke_type", 0));
        }


        //删除菜单的调度信息
        List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuFlowId).eq("job_type", 1));
        if (CollectionUtil.isNotEmpty(jobNodeConfs)) {
            jobNodeConfMapper.delete(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuFlowId).eq("job_type", 1));
        }

        return jobId;

    }

    private void deleteAllInfoByRealWorkMenuId(Long workMenuId) {
        //查询到任务
        RealTimeTask realTimeTask = realTimeTaskMapper.selectOne(new QueryWrapper<RealTimeTask>().eq("menu_id", workMenuId));
        if (null != realTimeTask) {
            List<FlinkTaskNode> flinkTaskNodes = flinkTaskNodeMapper.selectList(new QueryWrapper<FlinkTaskNode>().eq("task_id", workMenuId));
            if (CollectionUtil.isNotEmpty(flinkTaskNodes)) {
                List<Integer> ids = flinkTaskNodes.stream().map(i -> i.getId()).collect(Collectors.toList());
                List<FlinkNodeField> flinkNodeFields = flinkNodeFieldMapper.selectList(new QueryWrapper<FlinkNodeField>().in("node_id", ids));
                if (CollectionUtil.isNotEmpty(flinkNodeFields)) {
                    flinkNodeFieldMapper.delete(new QueryWrapper<FlinkNodeField>().in("node_id", ids));
                }
            }
            List<FlinkNodeUnion> flinkNodeUnions = flinkNodeUnionMapper.selectList(new QueryWrapper<FlinkNodeUnion>().eq("task_id", workMenuId));
            if (CollectionUtil.isNotEmpty(flinkNodeUnions)) {
                flinkNodeUnionMapper.delete(new QueryWrapper<FlinkNodeUnion>().eq("task_id", workMenuId));
            }
            List<BdpRealTaskAlarmObject> alarmObjects = realTaskAlarmObjectMapper.selectList(new QueryWrapper<BdpRealTaskAlarmObject>().eq("object_id", workMenuId));
            if (CollectionUtil.isNotEmpty(alarmObjects)) {
                realTaskAlarmObjectMapper.delete(new QueryWrapper<BdpRealTaskAlarmObject>().eq("object_id", workMenuId));
            }
        }

    }

    private void genWorkFlowLayAndConfig(WorkMenuAndLayDto parentWorkMenuAndLayDto, WorkMenuAndLayDto
            otherWorkFlow, Integer procId, Long newRootId,
                                         List<JobInfoDto> jobDtos, Long newMenuId, Long workDepId, Long logId) {

        //新增菜单目录
        WorkMenu workMenu = addWorkMenu(otherWorkFlow, parentWorkMenuAndLayDto.getNewId(), procId, newRootId, newMenuId);
        otherWorkFlow.setNewId(workMenu.getId());
        uploadVersionWorkflowResultLogMapper.updateWorkMenuId(workMenu.getId(), logId);

        //新增
        WorkFlowDep workFlowDep = addWorkDep(procId, workMenu.getId(), otherWorkFlow, workDepId);
        WorkFlowDepDto workFlowDepDto = otherWorkFlow.getWorkFlowDepDto();
        workFlowDepDto.setNewId(workFlowDep.getId());
        workFlowDepDto.setNewProcId(procId);
        workFlowDepDto.setNewWorkMenuId(workMenu.getId());

        //生成对应的虚拟化开始节点和结束节点的shell
        iWorkMenuService.saveStartJobNodeAndEndJobNode(procId.longValue(), workFlowDep.getId().intValue(), WorkFlowType.WORKFLOW_LAY.getCode());

        //编辑保存作业流依赖
        List<WorkMenuJobRel> workMenuJobRels = otherWorkFlow.getWorkMenuJobRels();
        JobLinkAndJobDto jobLinkAndJobDto = new JobLinkAndJobDto();
        jobLinkAndJobDto.setWorkFlowMenuId(workMenu.getId());
        jobLinkAndJobDto.setProcId(procId);
        jobLinkAndJobDto.setJobNodeConfig(otherWorkFlow.getJobNodeConfig());
        if (CollectionUtil.isNotEmpty(workMenuJobRels)) {
            List<JobLinkDto> edges = new ArrayList<>();
            List<JobInfoDto> nodes = new ArrayList<>();
            for (WorkMenuJobRel workMenuJobRel : workMenuJobRels) {
                JobInfoDto jobInfoDto = new JobInfoDto();
                jobInfoDto.setId(workMenuJobRel.getWorkFlowId().intValue());
                nodes.add(jobInfoDto);
            }
            //替换成新的id
            for (JobInfoDto node : nodes) {
                JobInfoDto jobInfoDto = jobDtos.stream().filter(o -> Objects.equals(node.getId(), o.getId())).findAny().orElse(null);
                if (null == jobInfoDto) {
                    throw new RRException("新建的工作流：【" + node.getId() + "】不存在！");
                }
                if (Objects.equals(1, jobInfoDto.getIsGenError())) {
                    throw new RRException("新建的工作流：【" + jobInfoDto.getName() + "】生成失败！");
                }
                node.setId(jobInfoDto.getNewId());
                node.setPosX(jobInfoDto.getPosX());
                node.setPosY(jobInfoDto.getPosY());
            }
            List<JobLink> jobLinks = otherWorkFlow.getJobLinks();
            //替换成新的id
            if (CollectionUtil.isNotEmpty(jobLinks)) {
                for (JobLink jobLink : jobLinks) {
                    JobInfoDto srcJobInfoDto = jobDtos.stream().filter(o -> Objects.equals(o.getId(), jobLink.getSrcNodeId())).findAny().orElse(null);
                    JobInfoDto dstJobInfoDto = jobDtos.stream().filter(o -> Objects.equals(o.getId(), jobLink.getDstNodeId())).findAny().orElse(null);
                    if (null == srcJobInfoDto || null == dstJobInfoDto) {
                        throw new RRException("源：【" + jobLink.getSrcNodeId() + "】或者目标工作流：【" + jobLink.getDstNodeId() + "】不存在！");
                    }
                    JobLinkDto jobLinkDto = new JobLinkDto();
                    jobLinkDto.setMenuId(workMenu.getId());
                    jobLinkDto.setLinkeType(1);
                    jobLinkDto.setCreateTime(DateTime.now());
                    jobLinkDto.setCreatePer(sysUserService.getUserId(jobLink.getCreatePerName(), ShiroUtils.getUserId().intValue()));
                    jobLinkDto.setDstNodeId(dstJobInfoDto.getNewId());
                    jobLinkDto.setSrcNodeId(srcJobInfoDto.getNewId());
                    edges.add(jobLinkDto);
                }
            }

            jobLinkAndJobDto.setNodes(nodes);
            jobLinkAndJobDto.setEdges(edges);
        }
        jobLinkAndJobDto.setIsImport(1);
        iWorkMenuService.updateWorkFlow(jobLinkAndJobDto, Boolean.FALSE);

        //启用工作流依赖---如果是启用状态的话
        if (null != workFlowDepDto && Objects.equals(workFlowDepDto.getJobLayStatus(), 1)) {
            try {
                iWorkMenuService.openWorkFlowJob(workMenu.getId());
            } catch (Exception e) {
                throw new RRException("启用作业流依赖【" + workMenu.getName() + "】异常！error:【" + e.getMessage() + "】");
            }
        }

    }

    private WorkFlowDep addWorkDep(Integer procId, Long workMenuId, WorkMenuAndLayDto otherWorkFlow, Long
            workDepId) {
        WorkFlowDep workFlowDep = new WorkFlowDep();
        workFlowDep.setProcId(procId);
        workFlowDep.setParam(null);
        workFlowDep.setWorkMenuId(workMenuId);
        workFlowDep.setLastRunState(null);
        workFlowDep.setCreateTime(LocalDateTime.now());
        workFlowDep.setDescName(otherWorkFlow.getDescName());
        workFlowDep.setJobLayStatus(0);
        workFlowDep.setCreatePer(sysUserService.getUserId(otherWorkFlow.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        if (null != workDepId) {
            workFlowDep.setId(workDepId);
            workFlowDepMapper.insertWorkFlowDep(workFlowDep);
        } else {
            workFlowDepMapper.insert(workFlowDep);
        }
        return workFlowDep;
    }

    private WorkMenu addWorkMenu(WorkMenuAndLayDto otherWorkFlow, Long parentId, Integer procId, Long
            newRootId, Long newMenuId) {
        WorkMenu workMenu = new WorkMenu();
        workMenu.setProcId(procId);
        workMenu.setParentId(parentId);
        workMenu.setWorkType(otherWorkFlow.getWorkType());
        if (null == newRootId) {
            WorkMenu workMenu1 = workMenuMapper.selectById(parentId);
            if (null != workMenu1) {
                newRootId = workMenu1.getRootId();
            }
        }
        workMenu.setRootId(newRootId);
        workMenu.setName(otherWorkFlow.getName());
        workMenu.setCreateTime(LocalDateTime.now());
        workMenu.setCreatePer(sysUserService.getUserId(otherWorkFlow.getCreatePerName(), ShiroUtils.getUserId().intValue()));
        if (null != newMenuId) {
            workMenu.setId(newMenuId);
            workMenuMapper.insertById(workMenu);
        } else {
            workMenuMapper.insert(workMenu);
        }
        return workMenu;
    }


//    private void copyRollbackData(CopyAllDataDto copyAllDataDto, List<String> errorList) {
//        //暂停掉对应的工作流和工作流依赖
////        stopWorkFlowAndWorkFlowLay(copyAllDataDto.getProcId(),errorList);
//        if(CollectionUtil.isNotEmpty(errorList)){
//            return;
//        }
//
//        //删除这个工程下所有的数据
////        deleteByProcId(copyAllDataDto.getProcId());
//
//        //开始重新生成对应的数据
////        genCopyRollbackData(copyAllDataDto,errorList);
//
//    }
//
//    private void genCopyRollbackData(CopyAllDataDto copyAllDataDto, List<String> errorList) {
//        if(null != copyAllDataDto){
//            //生成数据源（回滚），新增的删除掉，修改的（还原）
//
//
//
//
//            //生成仓库
//
//
//
//
//            //生成udf
//
//
//
//            //递归生成目录和工作流和工作流依赖
//            List<WorkMenu> allWorkMenus = copyAllDataDto.getAllWorkMenus();
//            if(CollectionUtil.isNotEmpty(allWorkMenus)){
//                Map<Long, List<WorkMenu>> rootGroupMaps = allWorkMenus.stream().collect(Collectors.groupingBy(WorkMenu::getRootId));
//                for(Map.Entry<Long, List<WorkMenu>> entry : rootGroupMaps.entrySet()){
//                    try {
//                        genRollbackData(entry,copyAllDataDto,errorList);
//                    }catch (Exception e){
//                        log.error("回滚工程错误！error:{}",e.getMessage());
//                        errorList.add("回滚工程错误！error:"+e.getMessage());
//                    }
//                }
//            }
//        }
//    }
//
//    private void genRollbackData(Map.Entry<Long, List<WorkMenu>> entry, CopyAllDataDto copyAllDataDto, List<String> errorList) {
//        if(null != entry){
//            Long workMenuId = entry.getKey();
//            List<WorkMenu> allWorkFlows = entry.getValue();
//            if(CollectionUtil.isNotEmpty(allWorkFlows)){
//                WorkMenu rootWorkMenu = allWorkFlows.stream().filter(o -> Objects.equals(o.getId(), workMenuId)).findAny().orElse(null);
//                if(null == rootWorkMenu){
//                    //错误数据
//                    return;
//                }
//                //新增根目录
//                workMenuMapper.insertById(rootWorkMenu);
//                List<WorkMenu> chrildrens = allWorkFlows.stream().filter(o -> Objects.equals(o.getParentId(), rootWorkMenu.getId())).collect(Collectors.toList());
//                List<WorkFlowDep> needGenWorkFlowLays = new ArrayList<>();
//                List<JobInfo> jobs = new ArrayList<>();
//                //生成文件
//                initChildrenData(chrildrens,allWorkFlows,copyAllDataDto,needGenWorkFlowLays,jobs,errorList);
//                if(CollectionUtil.isNotEmpty(needGenWorkFlowLays)){
//                    List<WorkMenuJobRel> allWorkMenuJobRels = copyAllDataDto.getAllWorkMenuJobRels();
//                    for (WorkFlowDep needGenWorkFlowLay : needGenWorkFlowLays) {
//                        //先编辑保存连线和配置信息
//                        JobLinkAndJobDto jobLinkAndJobDto = new JobLinkAndJobDto();
//                        jobLinkAndJobDto.setWorkFlowMenuId(needGenWorkFlowLay.getWorkMenuId());
//                        jobLinkAndJobDto.setProcId(needGenWorkFlowLay.getProcId());
//                        List<JobLink> allJobLinks = copyAllDataDto.getAllJobLinks();
//                        if(CollectionUtil.isNotEmpty(allJobLinks)){
//                            List<JobLink> jobLinks = allJobLinks.stream().filter(o -> (Objects.equals(o.getMenuId(), needGenWorkFlowLay.getWorkMenuId()) && Objects.equals(o.getLinkeType(), 1))).collect(Collectors.toList());
//                            jobLinkAndJobDto.setEdges(PojoUtils.listConvert(JobLinkDto.class, jobLinks));
//                        }
//                        if(CollectionUtil.isNotEmpty(jobs)){
//                            List<JobInfo> jobNodes = jobs.stream().filter(o -> (null != o.getPosY() && null != o.getPosX())).collect(Collectors.toList());
//                            //查询到这个job是这个作业流依赖里面
//                            if(CollectionUtil.isNotEmpty(jobNodes)){
//                                List<JobInfoDto> nodes = new ArrayList<>();
//                                for (JobInfo jobNode : jobNodes) {
//                                    List<WorkMenuJobRel> collect = allWorkMenuJobRels.stream().filter(o -> (Objects.equals(o.getWorkFlowId().intValue(), jobNode.getId())
//                                            && Objects.equals(2, o.getWorkType())
//                                            && Objects.equals(needGenWorkFlowLay.getWorkMenuId(), o.getWorkMenuId()))).collect(Collectors.toList());
//                                    if(CollectionUtil.isNotEmpty(collect)){
//                                        JobInfoDto jobInfoDto = new JobInfoDto();
//                                        BeanUtils.copyProperties(jobNode,jobInfoDto);
//                                        nodes.add(jobInfoDto);
//                                    }
//                                }
//                                if(CollectionUtil.isNotEmpty(nodes)){
//                                    jobLinkAndJobDto.setNodes(nodes);
//                                }
//                            }
//                        }
//                        List<JobNodeConf> allJobMenusConfs = copyAllDataDto.getAllJobMenusConfs();
//                        if(CollectionUtil.isNotEmpty(allJobMenusConfs)){
//                            List<JobNodeConf> jobNodeConfs = allJobMenusConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), needGenWorkFlowLay.getWorkMenuId().intValue())).collect(Collectors.toList());
//                            if(CollectionUtil.isNotEmpty(jobNodeConfs)){
//                                JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfs,1);
//                                if(null != jobNodeConfig){
//                                    jobLinkAndJobDto.setJobNodeConfig(jobNodeConfig);
//                                }
//                            }
//                        }
//                        try {
//                            iWorkMenuService.updateWorkFlow(jobLinkAndJobDto, Boolean.FALSE);
//                        }catch (Exception e){
//                            log.error("编辑保存作业流依赖【"+needGenWorkFlowLay.getWorkMenuId()+"】异常！error:{}",e.getMessage());
//                            errorList.add("编辑保存作业流依赖【"+needGenWorkFlowLay.getWorkMenuId()+"】异常！error:"+e.getMessage());
//                        }
//
//                        //再修改其启用禁用状态
//                        WorkFlowDep workFlowDep = workFlowDepMapper.selectById(needGenWorkFlowLay.getId());
//                        if(null != workFlowDep && !Objects.equals(workFlowDep.getJobLayStatus(),needGenWorkFlowLay.getJobLayStatus())){
//                            try {
//                                iWorkMenuService.openWorkFlowJob(needGenWorkFlowLay.getWorkMenuId());
//                            }catch (Exception e){
//                                log.error("启用作业流依赖【"+needGenWorkFlowLay.getWorkMenuId()+"】异常！error:{}",e.getMessage());
//                                errorList.add("启用作业流依赖【"+needGenWorkFlowLay.getWorkMenuId()+"】异常！error:"+e.getMessage());
//                            }
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//    private void initChildrenData(List<WorkMenu> chrildrens, List<WorkMenu> allWorkFlows, CopyAllDataDto copyAllDataDto, List<WorkFlowDep> needGenWorkFlowLays, List<JobInfo> jobs, List<String> errorList) {
//        if(CollectionUtil.isNotEmpty(chrildrens)){
//            for (WorkMenu chrildren : chrildrens) {
//                workMenuMapper.insertById(chrildren);
//                //特殊需要注意
//                if(Objects.equals(chrildren.getWorkType(),WorkFlowMenuType.WORKFLOW_FIELD.getCode())){
//                    // 生成对应的job和jobNode
//                    List<WorkMenuJobRel> allWorkMenuJobRels = copyAllDataDto.getAllWorkMenuJobRels();
//                    if(CollectionUtil.isNotEmpty(allWorkMenuJobRels)){
//                        try {
//                            WorkMenuJobRel workMenuJobRel = allWorkMenuJobRels.stream().filter(o -> (Objects.equals(o.getWorkType(), 1) && Objects.equals(o.getWorkMenuId(), chrildren.getId()))).findAny().orElse(null);
//                            if(null != workMenuJobRel){
//                                iWorkMenuJobRelService.saveOrUpdate(workMenuJobRel);
//                                // 虚拟化一个开始节点和一个结束节点，并且保存到hdfs上
//                                iWorkMenuService.saveStartNodeAndEndNode(chrildren.getProcId().longValue(), workMenuJobRel.getWorkFlowId().intValue(), WorkFlowType.WORKFLOW.getCode());
//                                // 新增任务
//                                List<JobInfo> allJobInfos = copyAllDataDto.getAllJobInfos();
//                                if(CollectionUtil.isNotEmpty(allJobInfos)){
//                                    JobInfo jobInfo = allJobInfos.stream().filter(o -> Objects.equals(o.getId(), workMenuJobRel.getWorkFlowId().intValue())).findAny().orElse(null);
//                                    if(null != jobInfo){
//                                        //任务信息需要置空
//                                        jobInfoMapper.insertJobInfo(jobInfo);
//                                        jobs.add(jobInfo);
//                                        //新增节点信息
//                                        List<JobNodeInfo> allJobNodeInfos = copyAllDataDto.getAllJobNodeInfos();
//                                        if(CollectionUtil.isNotEmpty(allJobNodeInfos)){
//                                            List<JobNodeInfo> jobNodes = allJobNodeInfos.stream().filter(o -> Objects.equals(o.getJobId(), jobInfo.getId())).collect(Collectors.toList());
//                                            if(CollectionUtil.isNotEmpty(jobNodes)){
//                                                //节点关联关系
//                                                List<WorkMenuJobRel> jobNodeRels = allWorkMenuJobRels.stream().filter(o -> Objects.equals(o.getWorkType(), 0)).collect(Collectors.toList());
//                                                if(CollectionUtil.isNotEmpty(jobNodeRels)){
//                                                    for (JobNodeInfo jobNode : jobNodes) {
//                                                        WorkMenuJobRel workMenuJobRel1 = jobNodeRels.stream().filter(o -> Objects.equals(o.getWorkFlowId().intValue(), jobNode.getId())).findAny().orElse(null);
//                                                        if(null != workMenuJobRel1) {
//                                                            workMenuJobRelMapper.batchInsert(Arrays.asList(workMenuJobRel1));
//                                                        }
//                                                    }
//                                                }
//                                                for (JobNodeInfo jobNode : jobNodes) {
//                                                    //任务信息需要清空
//                                                    jobNodeInfoMapper.insertJobNode(jobNode);
//
//                                                    //新增节点的配置信息
//                                                    List<JobNodeConf> allJobNodeConfs = copyAllDataDto.getAllJobNodeConfs();
//                                                    if(CollectionUtil.isNotEmpty(allJobNodeConfs)){
//                                                        List<JobNodeConf> jobNodeConfings = allJobNodeConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), jobNode.getId())).collect(Collectors.toList());
//                                                        JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfings,0);
//                                                        jobNode.setProcId(jobInfo.getProcId());
//                                                        if(null != jobNodeConfig){
//                                                            jobNode.setJobNodeConfig(jobNodeConfig);
//                                                            try {
//                                                                jobNodeInfoService.saveJobNodeConfig(jobNode);
//                                                            } catch (Exception e) {
//                                                                log.error("生成节点配置信息异常！error:{}",e.getMessage());
//                                                                throw new RRException(e.getMessage());
//                                                            }
//                                                        }
//                                                    }
//                                                }
//                                            }
//                                        }
//
//                                        //重新编辑保存任务(主要是连线)
//                                        JobLinkAndJobNodeDto jobLinkAndJobNodeDto = new JobLinkAndJobNodeDto();
//                                        jobLinkAndJobNodeDto.setWorkFlowMenuId(chrildren.getId());
//                                        jobLinkAndJobNodeDto.setProcId(chrildren.getProcId());
//                                        List<JobLink> allJobLinks = copyAllDataDto.getAllJobLinks();
//                                        if(CollectionUtil.isNotEmpty(allJobLinks)){
//                                            List<JobLink> jobLinks = allJobLinks.stream().filter(o -> (Objects.equals(o.getMenuId(), chrildren.getId()) && Objects.equals(o.getLinkeType(), 0))).collect(Collectors.toList());
//                                            jobLinkAndJobNodeDto.setEdges(PojoUtils.listConvert(JobLinkDto.class, jobLinks));
//                                        }
//                                        if(CollectionUtil.isNotEmpty(allJobNodeInfos)){
//                                            List<JobNodeInfo> jobNodes = allJobNodeInfos.stream().filter(o -> (Objects.equals(o.getJobId(), jobInfo.getId()) && null != o.getPosX())).collect(Collectors.toList());
//                                            jobLinkAndJobNodeDto.setNodes(PojoUtils.listConvert(JobNodeInfoDto.class, jobNodes));
//                                            if(CollectionUtil.isNotEmpty(jobNodes)){
//                                                //初始化需要路由重新保存的节点信息
//                                                List<JobNodeLayConfig> allJobNodeLayCongigs = copyAllDataDto.getAllJobNodeLayCongigs();
//                                                if(CollectionUtil.isNotEmpty(allJobNodeLayCongigs)){
//                                                    List<JobNodeLayConfig> jobNodeLays = allJobNodeLayCongigs.stream().filter(o -> Objects.equals(o.getJobId(), jobInfo.getId())).collect(Collectors.toList());
//                                                    if(CollectionUtil.isNotEmpty(jobNodeLays)){
//                                                        for (JobNodeLayConfig jobNodeLay : jobNodeLays) {
//                                                            if(null != jobNodeLay.getOutputTableId()){
//                                                                JobNodeInfo jobNodeInfo = jobNodes.stream().filter(o -> Objects.equals(o.getId(), jobNodeLay.getCurrentNodeId())).findAny().orElse(null);
//                                                                if(null != jobNodeInfo){
//                                                                    //新增节点的配置信息
//                                                                    List<JobNodeConf> allJobNodeConfs = copyAllDataDto.getAllJobNodeConfs();
//                                                                    if(CollectionUtil.isNotEmpty(allJobNodeConfs)){
//                                                                        List<JobNodeConf> jobNodeConfings = allJobNodeConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), jobNodeLay.getCurrentNodeId())).collect(Collectors.toList());
//                                                                        JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfings,0);
//                                                                        if(null != jobNodeConfig){
//                                                                            jobNodeInfo.setJobNodeConfig(jobNodeConfig);
//                                                                        }
//                                                                        List<JobNodeLayConfigDto> list = PojoUtils.listConvert(JobNodeLayConfigDto.class, Arrays.asList(jobNodeLay));
//                                                                        jobNodeInfo.setJobNodeLayConfigDtoList(list);
//                                                                        jobNodeInfo.setProcId(chrildren.getProcId());
//                                                                        try {
//                                                                            jobNodeInfoService.saveJobNodeConfig(jobNodeInfo);
//                                                                        } catch (Exception e) {
//                                                                            log.error("生成节点配置信息异常！error:{}",e.getMessage());
//                                                                            throw new RRException(e.getMessage());
//                                                                        }
//                                                                    }
//                                                                }
//                                                            }
//                                                        }
//                                                    }
//                                                }
//                                            }
//                                        }
//                                        List<JobNodeConf> allJobMenusConfs = copyAllDataDto.getAllJobMenusConfs();
//                                        if(CollectionUtil.isNotEmpty(allJobMenusConfs)){
//                                            List<JobNodeConf> jobNodeConfs = allJobMenusConfs.stream().filter(o -> Objects.equals(o.getJobNodeId(), chrildren.getId().intValue())).collect(Collectors.toList());
//                                            if(CollectionUtil.isNotEmpty(jobNodeConfs)){
//                                                JobNodeConfig jobNodeConfig = iBdpVersionService.listJobNodeConfigList(jobNodeConfs,1);
//                                                if(null != jobNodeConfig){
//                                                    jobLinkAndJobNodeDto.setJobNodeConfig(jobNodeConfig);
//                                                }
//                                            }
//                                        }
//                                        iWorkMenuService.updateWorkJob(jobLinkAndJobNodeDto);
//                                    }
//                                }
//                                //恢复对应的报警规则关联表数据
//                                List<AlarmObject> alarmObjects = copyAllDataDto.getAlarmObjects();
//                                if(CollectionUtil.isNotEmpty(alarmObjects)){
//                                    List<AlarmObject> collect = alarmObjects.stream().filter(o -> Objects.equals(o.getObjectId(), workMenuJobRel.getWorkMenuId().intValue())).collect(Collectors.toList());
//                                    if(CollectionUtil.isNotEmpty(collect)){
//                                        alarmObjectService.saveOrUpdateBatch(collect);
//                                    }
//                                }
//                            }
//                        }catch (Exception e){
//                            log.error("生成工作流:【"+chrildren.getName()+"】异常！error:{}",e.getMessage());
//                            errorList.add("生成工作流:【"+chrildren.getName()+"】异常！error:"+e.getMessage());
//                        }
//                    }
//                }else if(Objects.equals(chrildren.getWorkType(),WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())){
//                    List<WorkFlowDep> allWorkFlowDeps = copyAllDataDto.getAllWorkFlowDeps();
//                    if(CollectionUtil.isNotEmpty(allWorkFlowDeps)){
//                        WorkFlowDep workFlowDep = allWorkFlowDeps.stream().filter(o -> Objects.equals(o.getWorkMenuId(), chrildren.getId())).findAny().orElse(null);
//                        if(null != workFlowDep){
//                            //清空运行数据
//                            workFlowDepMapper.insertWorkFlowDep(workFlowDep);
//                            //生成对应的虚拟化开始节点和结束节点的shell
//                            iWorkMenuService.saveStartJobNodeAndEndJobNode(chrildren.getProcId().longValue(), workFlowDep.getId().intValue(), WorkFlowType.WORKFLOW_LAY.getCode());
//                            needGenWorkFlowLays.add(workFlowDep);
//                        }
//                    }
//                }else{
//                    List<WorkMenu> olderChrildrens = allWorkFlows.stream().filter(o -> Objects.equals(o.getParentId(), chrildren.getId())).collect(Collectors.toList());
//                    initChildrenData(olderChrildrens,allWorkFlows,copyAllDataDto, needGenWorkFlowLays, jobs, errorList);
//                }
//            }
//        }
//    }
//
//    private void deleteByProcId(Integer procId) {
//        //暂时只删除工作流和工作流依赖
//        List<WorkMenu> workMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
//        if(CollectionUtil.isNotEmpty(workMenus)){
//            List<WorkMenu> jobWorkMenus = workMenus.stream().filter(o -> Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())).collect(Collectors.toList());
//            List<WorkMenu> workMenuLays = workMenus.stream().filter(o -> Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())).collect(Collectors.toList());
//            //删除工作流相关
//            if(CollectionUtil.isNotEmpty(jobWorkMenus)){
//                //查询到工作流
//                Set<Long> workJobs = jobWorkMenus.stream().map(WorkMenu::getId).collect(Collectors.toSet());
//                List<WorkMenuJobRel> workMenuJobRels = workMenuJobRelMapper.selectByWorkMenuIds(workJobs);
//                if(CollectionUtil.isNotEmpty(workMenuJobRels)){
//                    List<WorkMenuJobRel> workMenuJobRels1 = workMenuJobRels.stream().filter(o -> Objects.equals(o.getWorkType(), 1)).collect(Collectors.toList());
//                    Set<Long> workFlowIds = workMenuJobRels1.stream().map(WorkMenuJobRel::getWorkMenuId).collect(Collectors.toSet());
//                    if(CollectionUtil.isNotEmpty(workFlowIds)){
//                        alarmObjectService.deleteWorkFlowRulesByWorkFlowIds(workFlowIds, Constant.AlarmTypeEnum.TASK_ALARM.getCode());
//                    }
//                    Set<Long> jobIds = workMenuJobRels1.stream().map(WorkMenuJobRel::getWorkFlowId).collect(Collectors.toSet());
//                    if(CollectionUtil.isNotEmpty(jobIds)){
//                        List<JobNodeInfo> jobNodeInfos = jobNodeInfoMapper.selectListByJobIds(jobIds);
//                        if(CollectionUtil.isNotEmpty(jobNodeInfos)){
//                            for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
//                                List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", jobNodeInfo.getId()).eq("job_type", 0));
//                                if(CollectionUtil.isNotEmpty(jobNodeConfs)){
//                                    jobNodeConfMapper.deleteBatchIds(jobNodeConfs.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
//                                }
//                                jobNodeLayConfigMapper.delete(new QueryWrapper<JobNodeLayConfig>().eq("current_node_id",jobNodeInfo.getId()));
//                                jobNodeInfoMapper.deleteById(jobNodeInfo.getId());
//                            }
//                        }
//                        jobInfoMapper.deleteBatchIds(jobIds);
//                    }
//                    for (WorkMenuJobRel workMenuJobRel : workMenuJobRels1) {
//                        List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuJobRel.getWorkMenuId()).eq("job_type", 1));
//                        if(CollectionUtil.isNotEmpty(jobNodeConfs)){
//                            jobNodeConfMapper.deleteBatchIds(jobNodeConfs.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
//                        }
//                        jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("linke_type",0).eq("menu_id",workMenuJobRel.getWorkMenuId()));
//                    }
//                    workMenuJobRelMapper.deleteBatchIds(workMenuJobRels1.stream().map(WorkMenuJobRel::getId).collect(Collectors.toSet()));
//                }
//                workMenuMapper.deleteBatchIds(workJobs);
//            }
//            //删除工作流依赖相关
//            if(CollectionUtil.isNotEmpty(workMenuLays)){
//                for (WorkMenu workMenuLay : workMenuLays) {
//                    List<JobNodeConf> jobNodeConfs = jobNodeConfMapper.selectList(new QueryWrapper<JobNodeConf>().eq("job_node_id", workMenuLay.getId()).eq("job_type", 1));
//                    if(CollectionUtil.isNotEmpty(jobNodeConfs)){
//                        jobNodeConfMapper.deleteBatchIds(jobNodeConfs.stream().map(JobNodeConf::getId).collect(Collectors.toList()));
//                    }
//                    jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("linke_type",1).eq("menu_id",workMenuLay.getId()));
//                    workFlowDepMapper.delete(new QueryWrapper<WorkFlowDep>().eq("work_menu_id",workMenuLay.getId()));
//                }
//            }
//            //删除菜单相关
//            Set<Long> allWorkMenus = workMenus.stream().map(WorkMenu::getId).collect(Collectors.toSet());
//            List<WorkMenuJobRel> workMenuJobRels11 = workMenuJobRelMapper.selectByWorkMenuIds(allWorkMenus);
//            if(CollectionUtil.isNotEmpty(workMenuJobRels11)){
//                Set<Long> collect = workMenuJobRels11.stream().map(WorkMenuJobRel::getId).collect(Collectors.toSet());
//                workMenuJobRelMapper.deleteBatchIds(collect);
//                for (Long aLong : collect) {
//                    workFlowDepMapper.delete(new QueryWrapper<WorkFlowDep>().eq("work_menu_id",aLong));
//                    jobLinkMapper.delete(new QueryWrapper<JobLink>().eq("menu_id",aLong));
//                }
//            }
//            workMenuMapper.deleteBatchIds(allWorkMenus);
//        }
//        workFlowDepMapper.delete(new QueryWrapper<WorkFlowDep>().eq("proc_id",procId));
//    }
//
//    private void stopWorkFlowAndWorkFlowLay(Integer procId, List<String> errorList) {
//        List<WorkFlowDep> workFlowDeps = workFlowDepMapper.selectList(new QueryWrapper<WorkFlowDep>().eq("proc_id", procId));
//        if(CollectionUtil.isNotEmpty(workFlowDeps)){
//            for (WorkFlowDep workFlowDep : workFlowDeps) {
//                if(Objects.equals(workFlowDep.getJobLayStatus(),1)){
//                    WorkMenu workMenu = workMenuMapper.selectById(workFlowDep.getWorkMenuId());
//                    String workLayName = null == workMenu ? "" : workMenu.getName();
//                    try {
//                        iWorkMenuService.closeWorkFlowJob(workFlowDep.getWorkMenuId());
//                    }catch (Exception e){
//                        log.error("禁用工作流依赖【"+ workLayName +"】异常！error:{}",e.getMessage());
//                        errorList.add("禁用工作流依赖【"+ workLayName +"】异常！error:" + e.getMessage());
//                    }
//                }
//            }
//        }
//        List<JobInfo> jobInfos = jobInfoMapper.selectList(new QueryWrapper<JobInfo>().eq("proc_id", procId));
//        if(CollectionUtil.isNotEmpty(jobInfos)){
//            for (JobInfo jobInfo : jobInfos) {
//                List<WorkMenuJobRel> workMenuJobRels = workMenuJobRelMapper.selectList(new QueryWrapper<WorkMenuJobRel>().eq("work_type", 1).eq("work_flow_id", jobInfo.getId()));
//                if(CollectionUtil.isNotEmpty(workMenuJobRels)){
//                    Set<Long> collect = workMenuJobRels.stream().map(WorkMenuJobRel::getWorkMenuId).collect(Collectors.toSet());
//                    if(CollectionUtil.isNotEmpty(collect)){
//                        for (Long aLong : collect) {
//                            try {
//                                iWorkMenuService.stopWorkJob(aLong,Boolean.TRUE);
//                            }catch (Exception e){
//                                log.error("暂停工作流【"+jobInfo.getName()+"】异常！error:{}",e.getMessage());
//                                errorList.add("暂停工作流【"+jobInfo.getName()+"】异常！error:" + e.getMessage());
//                            }
//
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//
//
//    @Override
//    public List<VersionStatusResultVO> cheackUploadVersionZipByVersionUUid(String versionUUid) {
//        //根据uuid查找到对应的zip文件
//        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", versionUUid));
//        if (null == uploadVersionLog) {
//            throw new RRException("上传的版本包不存在！");
//        }
//        VersionZipDto versionZipDto = getZipData(uploadVersionLog.getProcId(),versionUUid);
//        if (null == versionZipDto) {
//            log.error("上传的版本包解析json异常！");
//            throw new RRException("上传的版本包解析json异常！");
//        }
//
//        //将解析的结果和当前数据项目进行匹配，是否满足升级的条件。并且封装返回结果数据
//        //解析到所有的工作流
//        List<VersionStatusVO> allWorkFlowName = new ArrayList<>();
//        initAllWorkFlowNameAndLayName(versionZipDto.getWorkMenuList(),allWorkFlowName,Boolean.FALSE);
//        List<VersionStatusResultVO> filterList = new ArrayList<>();
//
//        //待返回
////        List<VersionStatusVO> olderRestList = new ArrayList<>();
//        //关联的数据源 : 用户和连接名字 同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变）
////        try {
////            genConnectList(versionZipDto,uploadVersionLog.getProcId(),olderRestList);
////        }catch (Exception e){
////            log.error("导入关联的数据源连接异常！error:{}",e.getMessage());
////        }
////        //关联的数据仓库 ：库和表  同一个环境（无，则新建；有，则不动）、不同环境（无，则新建；有，删除重建-id保持不变）
////        try {
////            genTableList(versionZipDto,uploadVersionLog.getProcId(),olderRestList);
////        }catch (Exception e){
////            log.error("导入关联的数据源连接异常！error:{}",e.getMessage());
////        }
////        if(CollectionUtil.isNotEmpty(olderRestList)){
////            log.error("导入数据源或者仓库异常！error:{}", olderRestList.toString());
////        }
//        List<VersionStatusVO> restVersionList = cheackCurrentDataToVersionData(versionZipDto,uploadVersionLog.getProcId());
//        if(CollectionUtil.isNotEmpty(allWorkFlowName)){
//            for (VersionStatusVO workFlowName : allWorkFlowName) {
//                if(CollectionUtil.isNotEmpty(restVersionList)){
//                    List<VersionStatusVO> collect = restVersionList.stream().filter(o -> Objects.equals(workFlowName.getName(), o.getName())).collect(Collectors.toList());
//                    if(CollectionUtil.isEmpty(collect)){
//                        VersionStatusVO versionStatusVO = pingVersionStatus(
//                                workFlowName.getErrorType(),
//                                null,
//                                null,
//                                workFlowName.getName(),
//                                2,
//                                workFlowName.getCreateName());
//                        VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                        BeanUtils.copyProperties(versionStatusVO,versionStatusResultVO);
//                        filterList.add(versionStatusResultVO);
//                    }else{
//                        VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                        versionStatusResultVO.setErrorType(collect.get(0).getErrorType());
//                        int errorNeedType = 2;
//                        long count = collect.stream().filter(o -> Objects.equals(o.getErrorNeedType(), 1)).count();
//                        if(count >= 1){
//                            errorNeedType = 1;
//                        }
//                        versionStatusResultVO.setErrorNeedType(errorNeedType);
//                        versionStatusResultVO.setName(workFlowName.getName());
//                        versionStatusResultVO.setCreateName(workFlowName.getCreateName());
//                        List<JSONObject> restList = new ArrayList<>();
//                        restList.addAll(collect.stream().filter(o -> Objects.equals(o.getErrorNeedType(), 1)).map(VersionStatusVO::getErrorObjs).collect(Collectors.toList()));
//                        versionStatusResultVO.setErrorObjLists(restList);
//                        filterList.add(versionStatusResultVO);
//                    }
//                }else{
//                    VersionStatusVO versionStatusVO = pingVersionStatus(
//                            workFlowName.getErrorType(),
//                            null,
//                            null,
//                            workFlowName.getName(),
//                            2,
//                            workFlowName.getCreateName());
//                    VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                    BeanUtils.copyProperties(versionStatusVO,versionStatusResultVO);
//                    filterList.add(versionStatusResultVO);
//                }
//            }
//        }
//        return filterList;
//    }
//
//    private void initAllWorkFlowNameAndLayName(List<WorkMenuAndLayDto> workMenuList, List<VersionStatusVO> allWorkFlowName, Boolean afalg) {
//        if(CollectionUtil.isNotEmpty(workMenuList)){
//            Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = workMenuList.stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
//            //按照根菜单进行名字查找看是否存在。当前工程下
//            for(Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()){
//                List<WorkMenuAndLayDto> rootWorkMenus = entry.getValue();
//                if(CollectionUtil.isNotEmpty(rootWorkMenus)){
//                    Long olderRootId = entry.getKey();
//                    List<WorkMenuAndLayDto> olderWorkMenus = entry.getValue();
//                    if(null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)){
//                        WorkMenuAndLayDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
//                        if(null != workMenuAndLayDto){
//                            StringBuffer sbWorkMenuName = new StringBuffer();
//                            List<WorkMenuAndLayDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
//                            //根目录的名字
//                            sbWorkMenuName.append(workMenuAndLayDto.getName());
//                            initChildrenName(olderChildrens,olderWorkMenus,allWorkFlowName,afalg,sbWorkMenuName);
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//    private void initChildrenName(List<WorkMenuAndLayDto> olderChildrens, List<WorkMenuAndLayDto> olderWorkMenus, List<VersionStatusVO> allWorkFlowName, Boolean afalg, StringBuffer sbWorkMenuName) {
//        if(CollectionUtil.isNotEmpty(olderChildrens)){
//            if(CollectionUtil.isNotEmpty(olderChildrens)) {
//                for (WorkMenuAndLayDto olderChildren : olderChildrens) {
//                    StringBuffer olderTemp = new StringBuffer(sbWorkMenuName);
//                    StringBuffer newTemp = olderTemp.append("/").append(olderChildren.getName());
//                    if (Objects.equals(olderChildren.getWorkType(), WorkFlowMenuType.WORKFLOW_FIELD.getCode())) {
//                        allWorkFlowName.add(pingVersionStatus(
//                                ErrorType.WORKFLOW.getCode(),
//                                ErrorType.WORKFLOW.getName(),
//                                null,
//                                newTemp.toString(),
//                                2,
//                                olderChildren.getCreatePerName()));
//                    }else if(Objects.equals(olderChildren.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())){
//                        if(afalg){
//                            allWorkFlowName.add(pingVersionStatus(
//                                    ErrorType.WORKFLOWLAY.getCode(),
//                                    ErrorType.WORKFLOWLAY.getName(),
//                                    null,
//                                    newTemp.toString(),
//                                    2,
//                                    olderChildren.getCreatePerName()));
//                        }
//                    }else{
//                        List<WorkMenuAndLayDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
//                        initChildrenName(olderChildrens1,olderWorkMenus,allWorkFlowName,afalg,newTemp);
//                    }
//                }
//            }
//        }
//    }
//
//    @Override
//    public List<VersionStatusResultVO> importData(String versionUUid) {
//
//        UploadVersionLog uploadVersionLog = uploadVersionLogMapper.selectOne(new QueryWrapper<UploadVersionLog>().eq("zip_path_name", versionUUid));
//        if (null == uploadVersionLog) {
//            throw new RRException("上传的版本包不存在！");
//        }
//        //查询是否备份过
//        BdpVersion bdpVersion = iBdpVersionService.getOne(new QueryWrapper<BdpVersion>().eq("version_type", VersionType.BACKUPS.getCode()).eq("up_zip_path_name", uploadVersionLog.getZipPathName()));
//        if(null != bdpVersion){
//           //删除数据和删除对应的zip文件
//            deleteVersion(bdpVersion.getId(),uploadVersionLog.getProcId(),bdpVersion.getUpZipPathName());
//        }
//        //重新先备份当前工程下所有的数据信息，并且打成zip包 保存起来
//        BdpAddVersionDto bdpAddVersionDto = new BdpAddVersionDto();
//        String currentTime = TimeUtil.getCurrentTime();
//        bdpAddVersionDto.setVersionName("auto-" + currentTime);
//        bdpAddVersionDto.setVersionNum("auto-V-" + currentTime);
//        bdpAddVersionDto.setCreatePer(ShiroUtils.getUserId().intValue());
//        bdpAddVersionDto.setVersionType(VersionType.BACKUPS.getCode());
//        bdpAddVersionDto.setProcId(uploadVersionLog.getProcId());
//        bdpAddVersionDto.setUpZipPathName(uploadVersionLog.getZipPathName());
//        BdpVersion bdpVersion1 = iBdpVersionService.copyVersion(bdpAddVersionDto);
//        //重新先备份当前工程下所有的数据信息，并且上传到hdfs上
//        CopyAllDataDto copyAllDataDto = listAllCopyData(uploadVersionLog.getProcId(), null);
//        //上传文件
//        try {
//            HdfsUtil hdfsUtil = new HdfsUtil(bdpJobConfig);
//            String uploadPath = String.format("%s/%s/%s/%s", bdpJobConfig.getVersion(), uploadVersionLog.getProcId(), bdpVersion1.getId(),uploadVersionLog.getZipPathName() + ".json");
//            hdfsUtil.writeFile(JSONObject.toJSONString(copyAllDataDto).getBytes("utf-8"), uploadPath);
//            hdfsUtil.close();
//        } catch (Exception e) {
//            log.error("备份文件异常！error:{}", e.getMessage());
//            throw new RRException("备份文件异常！");
//        }
//        //保存备份的json信息
//        BdpVersionProcRel bdpVersionProcRel = new BdpVersionProcRel();
//        bdpVersionProcRel.setVersionId(bdpVersion1.getId());
//        bdpVersionProcRel.setProcId(uploadVersionLog.getProcId());
//        bdpVersionProcRel.setAllCopyDataJson(JSONObject.toJSONString(copyAllDataDto));
//        bdpVersionProcRelMapper.insert(bdpVersionProcRel);
//
//
//        VersionZipDto versionZipDto = getZipData(uploadVersionLog.getProcId(),versionUUid);
//        if (null == versionZipDto) {
//            log.error("上传的版本包解析json异常！");
//            throw new RRException("上传的版本包解析json异常！");
//        }
//
//        List<VersionStatusVO> allWorkFlowName = new ArrayList<>();
//        initAllWorkFlowNameAndLayName(versionZipDto.getWorkMenuList(),allWorkFlowName,Boolean.TRUE);
//        List<VersionStatusVO> restList = new ArrayList<>();
//
//        //作业流和作业流依赖
//        VersionChangeModelDto versionChangeModelDto = null;
//        try {
//            //暂时去掉导入工作流的东西
//            versionChangeModelDto = genWorkFlowByPack(versionZipDto,uploadVersionLog.getProcId(),restList);
//        }catch (Exception e){
//            log.error("导入作业流和作业流依赖异常！error:{}",e.getMessage());
//            deleteVersion(bdpVersion.getId(),uploadVersionLog.getProcId(),bdpVersion.getUpZipPathName());
//            //导入是成功还是失败
//            updateUploadVersionLog(1,uploadVersionLog);
//            throw new RRException("导入作业流和作业流依赖异常！error:"+e.getMessage());
//        }
//        //保存改变的记录信息
//        VersionChangeLogDto versionChangeLogDto = new VersionChangeLogDto();
//        versionChangeLogDto.setUpVersionLogId(uploadVersionLog.getId());
////        versionChangeLogDto.setConnectLogJson();
////        versionChangeLogDto.setTableLogJson();
////        versionChangeLogDto.setUdfLogJson();
//        versionChangeLogDto.setWorkflowLogJson(JSONObject.toJSONString(versionChangeModelDto));
//        VersionChangeLog versionChangeLog = new VersionChangeLog();
//        BeanUtils.copyProperties(versionChangeLogDto,versionChangeLog);
//        versionChangeLogMapper.insert(versionChangeLog);
//
//
//        List<VersionStatusResultVO> newRestList = new ArrayList<>();
//        Integer successed = 0;
//        if(CollectionUtil.isNotEmpty(allWorkFlowName)){
//            for (VersionStatusVO name : allWorkFlowName) {
//                if(CollectionUtil.isNotEmpty(restList)){
//                    List<VersionStatusVO> collect = restList.stream().filter(o -> Objects.equals(name.getName(), o.getName())).collect(Collectors.toList());
//                    if(CollectionUtil.isEmpty(collect)){
//                        VersionStatusVO versionStatusVO = pingVersionStatus(
//                                name.getErrorType(),
//                                null,
//                                null,
//                                name.getName(),
//                                2,
//                                name.getCreateName());
//                        VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                        BeanUtils.copyProperties(versionStatusVO,versionStatusResultVO);
//                        newRestList.add(versionStatusResultVO);
//                    }else{
//                        VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                        versionStatusResultVO.setErrorType(collect.get(0).getErrorType());
//                        int errorNeedType = 2;
//                        long count = collect.stream().filter(o -> Objects.equals(o.getErrorNeedType(), 1)).count();
//                        if(count >= 1){
//                            errorNeedType = 1;
//                            successed = 1;
//                        }
//                        versionStatusResultVO.setErrorNeedType(errorNeedType);
//                        versionStatusResultVO.setName(name.getName());
//                        versionStatusResultVO.setCreateName(name.getCreateName());
//                        List<JSONObject> restList1 = new ArrayList<>();
//                        restList1.addAll(collect.stream().map(VersionStatusVO::getErrorObjs).collect(Collectors.toList()));
//                        versionStatusResultVO.setErrorObjLists(restList1);
//                        newRestList.add(versionStatusResultVO);
//                    }
//                }else{
//                    VersionStatusVO versionStatusVO = pingVersionStatus(
//                            name.getErrorType(),
//                            null,
//                            null,
//                            name.getName(),
//                            2,
//                            name.getCreateName());
//                    VersionStatusResultVO versionStatusResultVO = new VersionStatusResultVO();
//                    BeanUtils.copyProperties(versionStatusVO,versionStatusResultVO);
//                    newRestList.add(versionStatusResultVO);
//                }
//            }
//        }
//        //导入是成功还是失败
//        updateUploadVersionLog(successed,uploadVersionLog);
//
//        return newRestList;
//    }


//    private void updateUploadVersionLog(Integer successed, UploadVersionLog uploadVersionLog) {
//        uploadVersionLog.setUpZipStatus(successed);
//        uploadVersionLogMapper.updateById(uploadVersionLog);
//    }
//    private void deleteVersion(Long id, Integer procId, String upZipPathName) {
//        iBdpVersionService.removeById(id);
//        try {
//            String uploadPath = String.format("%s/%s/%s", bdpJobConfig.getVersion(), procId, upZipPathName);
//            HdfsUtil hdfsUtil = new HdfsUtil(bdpJobConfig);
//            hdfsUtil.delete(uploadPath);
//            hdfsUtil.close();
//        } catch (Exception e) {
//            log.error("删除备份的资源文件:{}异常！error:{}", upZipPathName, e.getMessage());
//        }
//    }
//
//    private VersionChangeModelDto genWorkFlowByPack(VersionZipDto versionZipDto, Integer procId, List<VersionStatusVO> restList) {
//        //打包数据,封装变化的数据
//        List<WorkMenuAndLayDto> workMenuList = versionZipDto.getWorkMenuList();
//        if(CollectionUtil.isEmpty(workMenuList)){
//            return null;
//        }
//        //查询到当前工程下对应的菜单
//        List<WorkMenu> newWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
//        //一层一层来生成
//        Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = workMenuList.stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
//        //按照根菜单进行名字查找看是否存在。当前工程下
//        List<List<WorkMenuAndLayDto>> packWorkMenuAndLayDtoLists = new ArrayList<>();
//        for(Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()){
//            List<WorkMenuAndLayDto> tempList = genPackWorkMenus(entry,newWorkMenus);
//            if(CollectionUtil.isNotEmpty(tempList)){
//                packWorkMenuAndLayDtoLists.add(tempList);
//            }
//        }
//        //根据结果，来生成和修改菜单树和对应的工作流和工作流依赖
//        if(CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoLists)){
//            VersionChangeModelDto versionChangeModelDto = new VersionChangeModelDto();
//            for (List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList : packWorkMenuAndLayDtoLists) {
//                //已每个根目录为单位,进行生成菜单树和对应的节点信息和对应的工作流和工作流依赖信息
//                try {
//                    genWorkFlowData(packWorkMenuAndLayDtoList,versionChangeModelDto,procId,versionZipDto,restList);
//                }catch (Exception e){
//                    log.error("生成根目录失败！error:{}",e.getMessage());
//                    JSONObject jsonObject = new JSONObject();
//                    jsonObject.put("根目录生成工作流异常,根目录：【" + packWorkMenuAndLayDtoList.get(0).getName() + "】",e.getMessage());
//                    versionChangeModelDto.getErrorWorkMenuList().add(jsonObject);
//
//                    restList.add(pingVersionStatus(
//                            6,
//                            "工程",
//                            e.getMessage(),
//                            packWorkMenuAndLayDtoList.get(0).getName(),
//                            1,
//                            packWorkMenuAndLayDtoList.get(0).getCreatePerName()));
//
//                    //删除这个新的改变（回滚）
//                    deleteAllInfoByRootWorkMenuId(packWorkMenuAndLayDtoList);
//                }
//            }
//            return versionChangeModelDto;
//        }
//        return null;
//    }
//
//    private void deleteAllInfoByRootWorkMenuId(List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList) {
//        if(CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoList)) {
//            //挑选出作业流依赖的集合，其它的菜单目录先生成完成以后，再生成对应的作业流依赖
//            List<WorkMenuAndLayDto> workFlowLays = new ArrayList<>();
//            List<WorkMenuAndLayDto> otherWorkFlows = new ArrayList<>();
//            packWorkMenuAndLayDtoList.forEach(o -> {
//                if (Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())) {
//                    workFlowLays.add(o);
//                } else {
//                    otherWorkFlows.add(o);
//                }
//            });
//            //删除作业流依赖
//            if(CollectionUtil.isNotEmpty(workFlowLays)){
//                for (WorkMenuAndLayDto otherWorkFlow : workFlowLays) {
//                    deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
//                }
//            }
//            if(CollectionUtil.isNotEmpty(otherWorkFlows)){
//                WorkMenu workMenuLay = new WorkMenu();
//                for (WorkMenuAndLayDto workMenuAndLayDto : otherWorkFlows) {
//                    if(Objects.equals(workMenuAndLayDto.getWorkType(),WorkFlowMenuType.WORKFLOW_FIELD.getCode())){
//                        deleteAllInfoByWorkMenuId(workMenuAndLayDto.getNewId(), new ArrayList<JobNodeInfo>(), workMenuLay);
//                    }else{
//                        workMenuMapper.deleteById(workMenuAndLayDto.getNewId());
//                    }
//                }
//            }
//
//        }
//    }
//
//    private void genWorkFlowData(List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList, VersionChangeModelDto versionChangeModelDto, Integer procId, VersionZipDto versionZipDto, List<VersionStatusVO> restList) throws Exception {
//        if(CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoList)){
//            //挑选出作业流依赖的集合，其它的菜单目录先生成完成以后，再生成对应的作业流依赖
//            List<WorkMenuAndLayDto> workFlowLays = new ArrayList<>();
//            List<WorkMenuAndLayDto> otherWorkFlows = new ArrayList<>();
//            packWorkMenuAndLayDtoList.forEach(o -> {
//                if(Objects.equals(o.getWorkType(), WorkFlowMenuType.WORKFLOW_MGT_FIELD.getCode())){
//                    workFlowLays.add(o);
//                }else{
//                    otherWorkFlows.add(o);
//                }
//            });
//            //生成对应的菜单和对应的工作流和节点
//            Long newRootId = 0L;
//            List<JobInfoDto> jobDtos = new ArrayList<>();
//
//            if(CollectionUtil.isNotEmpty(otherWorkFlows)){
//                //先排序，让菜单的顺序一样
//                List<WorkMenuAndLayDto> dataList = otherWorkFlows.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
//                for (WorkMenuAndLayDto otherWorkFlow : dataList) {
//                    String append = getWorkMenuName(otherWorkFlow,packWorkMenuAndLayDtoList);
//                    //根目录
//                    if(Objects.equals(0L,otherWorkFlow.getParentId())){
//                        if(null == otherWorkFlow.getNewId()){
//                            WorkMenu one = addRootWorkMenuDto(otherWorkFlow,procId);
//                            JSONObject jsonObject = new JSONObject();
//                            jsonObject.put("bdp_work_menu",JSONObject.toJSONString(one));
//                            versionChangeModelDto.getAddList().add(jsonObject);
//
//                            //重置新的id
//                            otherWorkFlow.setNewRootId(one.getId());
//                            otherWorkFlow.setNewProcId(Long.valueOf(procId));
//                            otherWorkFlow.setNewParentId(0L);
//                            otherWorkFlow.setNewId(one.getId());
//                            newRootId = one.getId();
//                        }else{
//                            newRootId = otherWorkFlow.getNewRootId();
//                        }
//                    }
//                    //子目录 或者 作业流血缘管理文件夹
//                    if(Objects.equals(otherWorkFlow.getWorkType(),WorkFlowMenuType.SUB_DIR.getCode())
//                    || Objects.equals(otherWorkFlow.getWorkType(),WorkFlowMenuType.WORKFLOW_MGT.getCode())
//                            || Objects.equals(otherWorkFlow.getWorkType(),WorkFlowMenuType.SUB_SUB_DIR.getCode())){
//                        if(null == otherWorkFlow.getNewId()){
//                            WorkMenuAndLayDto workMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
//                            WorkMenu subOne = addWorkFlowMGTAndSubDto(otherWorkFlow,procId,workMenuAndLayDto.getNewId(),newRootId);
//                            JSONObject jsonObject = new JSONObject();
//                            jsonObject.put("bdp_work_menu",JSONObject.toJSONString(subOne));
//                            versionChangeModelDto.getAddList().add(jsonObject);
//
//                            //重置新的id
//                            otherWorkFlow.setNewRootId(subOne.getRootId());
//                            otherWorkFlow.setNewProcId(Long.valueOf(procId));
//                            otherWorkFlow.setNewParentId(workMenuAndLayDto.getNewId());
//                            otherWorkFlow.setNewId(subOne.getId());
//                        }
//                    }
//
//                    //作业流文件夹
//                    if(Objects.equals(otherWorkFlow.getWorkType(),WorkFlowMenuType.WORKFLOW_FIELD.getCode())){
//                        //先生成文件夹，再生成节点，在生成工作流，再启动任务
//                        WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getId(), otherWorkFlow.getParentId())).findAny().orElse(null);
//                        if(null == otherWorkFlow.getNewId()){
//                            //新增作业流和其任务和对应的节点和配置信息
//                            try {
//                                //genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto,otherWorkFlow,procId,newRootId,versionChangeModelDto,versionZipDto,jobDtos, null, null, null);
//                            }catch (Exception e){
//                                log.error("生成工作流:{}异常error:{}",otherWorkFlow.getName(),e.getMessage());
//                                restList.add(pingVersionStatus(
//                                        ErrorType.WORKFLOW.getCode(),
//                                        ErrorType.WORKFLOW.getName(),
//                                        "生成工作流:"+otherWorkFlow.getName()+"异常error:"+e.getMessage(),
//                                        append,
//                                        1,
//                                        otherWorkFlow.getCreatePerName()));
//                                WorkMenu workMenuLay = new WorkMenu();
//                                //先删除数据，然后再新增
//                                deleteAllInfoByWorkMenuId(otherWorkFlow.getNewId(), new ArrayList<JobNodeInfo>(), workMenuLay);
//                            }
//                        } else {
//                            //先删除数据，然后再新增
//                            List<JobNodeInfo> olderJobNodeInfos = new ArrayList<>();
//                            WorkMenu workMenuLay = new WorkMenu();
//                            Integer jobId = deleteAllInfoByWorkMenuId(otherWorkFlow.getNewId(), olderJobNodeInfos, workMenuLay);
//                            try {
//                             //genWorkFlowAndJobNodeAndConfig(parentWorkMenuAndLayDto,otherWorkFlow,procId,newRootId,versionChangeModelDto,versionZipDto,jobDtos,olderJobNodeInfos,otherWorkFlow.getNewId(), jobId);
//                            }catch (Exception e){
//                                log.error("生成工作流:{}异常error:{}",otherWorkFlow.getName(),e.getMessage());
//                                restList.add(pingVersionStatus(
//                                        ErrorType.WORKFLOW.getCode(),
//                                        ErrorType.WORKFLOW.getName(),
//                                        "生成工作流:"+otherWorkFlow.getName()+"异常error:"+e.getMessage(),
//                                        append,
//                                        1,
//                                        otherWorkFlow.getCreatePerName()));
//
//                                //先删除数据，然后再新增
//                                deleteAllInfoByWorkMenuId(otherWorkFlow.getNewId(),new ArrayList<JobNodeInfo>(), workMenuLay);
//                            }
//                        }
//                    }
//                }
//            }
//            //生成对应的作业流依赖
//            if(CollectionUtil.isNotEmpty(workFlowLays)){
//                //生成作业流依赖
//                WorkMenuAndLayDto parentWorkMenuAndLayDto = otherWorkFlows.stream().filter(o -> Objects.equals(o.getWorkType(),WorkFlowMenuType.WORKFLOW_MGT.getCode())).findAny().orElse(null);
//                //先排序，让菜单的顺序一样
//                List<WorkMenuAndLayDto> workFlowList = workFlowLays.stream().sorted(Comparator.comparing(WorkMenuAndLayDto::getId)).collect(Collectors.toList());
//                for (WorkMenuAndLayDto otherWorkFlow : workFlowList) {
//                    String append1 = getWorkMenuName(otherWorkFlow,packWorkMenuAndLayDtoList);
//                    //先生成文件夹，再生成配置信息，再配置作业流依赖，再启动作业流依赖
//                    if(null == otherWorkFlow.getNewId()){
//                        try {
//                            //genWorkFlowLayAndConfig(parentWorkMenuAndLayDto,otherWorkFlow,procId,newRootId,versionChangeModelDto,versionZipDto,jobDtos,null);
//                        }catch (Exception e){
//                            log.error("生成工作流依赖:{}异常error:{}",otherWorkFlow.getName(),e.getMessage());
//                            restList.add(pingVersionStatus(
//                                    ErrorType.WORKFLOWLAY.getCode(),
//                                    ErrorType.WORKFLOWLAY.getName(),
//                                    "生成工作流依赖:"+otherWorkFlow.getName()+"异常error:"+e.getMessage(),
//                                    append1,
//                                    1,
//                                    otherWorkFlow.getCreatePerName()));
//                            //先删除后新增
//                            deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
//                        }
//
//                    } else{
//                        //先删除后新增
//                        deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
//                        try {
//                            //genWorkFlowLayAndConfig(parentWorkMenuAndLayDto,otherWorkFlow,procId,newRootId,versionChangeModelDto,versionZipDto,jobDtos,otherWorkFlow.getNewId());
//                        }catch (Exception e){
//                            log.error("生成工作流依赖:{}异常error:{}",otherWorkFlow.getName(),e.getMessage());
//                            restList.add(pingVersionStatus(
//                                    ErrorType.WORKFLOWLAY.getCode(),
//                                    ErrorType.WORKFLOWLAY.getName(),
//                                    "生成工作流依赖:"+otherWorkFlow.getName()+"异常error:"+e.getMessage(),
//                                    append1,
//                                    1,
//                                    otherWorkFlow.getCreatePerName()));
//                            //先删除后新增
//                            deleteAllInfoByWorkMenuLayId(otherWorkFlow.getNewId());
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//    private String getWorkMenuName(WorkMenuAndLayDto otherWorkFlow, List<WorkMenuAndLayDto> packWorkMenuAndLayDtoList) {
//        if(CollectionUtil.isNotEmpty(packWorkMenuAndLayDtoList) && null != otherWorkFlow){
//            List<WorkMenuAndLayDto> listDatas = new ArrayList<>();
//            WorkMenuAndLayDto newWork = new WorkMenuAndLayDto();
//            BeanUtils.copyProperties(otherWorkFlow,newWork);
//            listDatas.add(newWork);
//            Boolean flage = Boolean.TRUE;
//            WorkMenuAndLayDto workMenuAndLayDto = otherWorkFlow;
//            while (flage){
//                WorkMenuAndLayDto finalWorkMenuAndLayDto = workMenuAndLayDto;
//                workMenuAndLayDto = packWorkMenuAndLayDtoList.stream().filter(o -> Objects.equals(o.getId(), finalWorkMenuAndLayDto.getParentId())).findAny().orElse(null);
//                if(null != workMenuAndLayDto){
//                    listDatas.add(workMenuAndLayDto);
//                }else{
//                    flage = Boolean.FALSE;
//                }
//            }
//            StringBuffer temps = new StringBuffer();
//            if(CollectionUtil.isNotEmpty(listDatas)){
//                for(int i = listDatas.size() -1 ; i >= 0; i--){
//                    temps.append(listDatas.get(i).getName()).append("/");
//                }
//                return temps.toString().substring(0,temps.toString().length()-1);
//            }
//        }
//        return null;
//    }
//
//    private void genJobNodeAndConfig(WorkMenuAndLayDto parentWorkMenuAndLayDto, WorkMenuAndLayDto otherWorkFlow, Integer procId, Long newRootId, VersionZipDto versionZipDto, List<JobInfoDto> jobDtos, List<JobNodeInfo> olderJobNodeInfos, Long workMenuNewId, Integer jobId) throws Exception {
//        //新增作业流菜单目录
//        WorkMenu workMenu = addDefaultWorkFlowMenu(otherWorkFlow,procId,parentWorkMenuAndLayDto.getNewId(),newRootId,workMenuNewId,jobId);
//        otherWorkFlow.setNewId(workMenu.getId());
//
//        //关联表
//        WorkMenuJobRel workMenuJobRel = workMenuJobRelMapper.selectOne(new QueryWrapper<WorkMenuJobRel>()
//                .eq("proc_id", procId)
//                .eq("work_menu_id", workMenu.getId())
//                .eq("work_type", 1));
//        //jobInfo表
//        JobInfo jobInfo = jobInfoMapper.selectById(workMenuJobRel.getWorkFlowId());
//
//        JobInfoDto jobInfoDto = otherWorkFlow.getJobInfoDto();
//        if(null != jobInfoDto){
//            jobInfoDto.setNewId(jobInfo.getId());
//        }
//        jobDtos.add(jobInfoDto);
//
//
//
//        //重置新的id
//        otherWorkFlow.setNewRootId(workMenu.getRootId());
//        otherWorkFlow.setNewProcId(Long.valueOf(procId));
//        otherWorkFlow.setNewParentId(parentWorkMenuAndLayDto.getNewId());
//        otherWorkFlow.setNewId(workMenu.getId());
//
//        //新增空的jobNode
//        List<JobNodeInfoDto> nodes = new ArrayList<>();
//        List<JobNodeInfo> newJobNodeInfos = new ArrayList<>();
//        if(null != jobInfoDto && CollectionUtil.isNotEmpty(jobInfoDto.getJobNodeInfos())){
//            List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
//            for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
//                if(!Objects.equals(JobType.INPUT.getCode(),jobNodeInfo.getTypeId())
//                        && !Objects.equals(JobType.SQL.getCode(),jobNodeInfo.getTypeId())
//                        && !Objects.equals(JobType.OUTPUT.getCode(),jobNodeInfo.getTypeId())){
//                    continue;
//                }
//                JobNodeInfo newJobNodeInfo = addJobNodeInfo(jobNodeInfo,jobInfo.getId(),procId);
//                jobNodeInfo.setNewId(newJobNodeInfo.getId());
//                jobNodeInfo.setNewJobId(jobInfo.getId());
//                if(null != newJobNodeInfo.getPosY() && null != newJobNodeInfo.getPosX()){
//                    JobNodeInfoDto jobNodeInfoDto  = new JobNodeInfoDto();
//                    BeanUtils.copyProperties(newJobNodeInfo,jobNodeInfoDto);
//                    nodes.add(jobNodeInfoDto);
//                }
//                //生成关联关系
//                WorkMenuJobRel workMenuJobRel1 = addWorkMenuJobRel(newJobNodeInfo.getId(),workMenu.getId(),procId);
//
//                //生成节点的配置信息
//                JobNodeConfig jobNodeConfig = jobNodeInfo.getJobNodeConfig();
//                if(null != jobNodeConfig){
//                    //节点中所有的数据源id和表id都需要改
//                    jobNodeConfig.setJobNodeId(newJobNodeInfo.getId());
//                    if(Objects.equals(newJobNodeInfo.getTypeId(), JobType.INPUT.getCode())){
//                        //连接id
//                        List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
//                        if(CollectionUtil.isEmpty(connectList)){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getInput_connect_id()+"】不存在！");
//                        }
//                        ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getInput_connect_id(), o.getId())).findAny().orElse(null);
//                        if(null == confConnectAndConfigDto){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getInput_connect_id()+"】不存在！");
//                        }
//                        Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
//                        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>().eq("name", confConnectAndConfigDto.getName()).eq("create_per",userId));
//                        if(null == confConnect){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnectAndConfigDto.getName()+"】不存在！");
//                        }
//                        jobNodeConfig.setInput_connect_id(confConnect.getId());
//                        if(Objects.equals(confConnect.getTypeId(), ConnectTypeEnum.Sap.getCode())){
//                            //bdp_sap_connect_field 需要改变id
//                            SapConnectField sapConnectFieldInfo = jobNodeConfig.getSapConnectFieldInfo();
//                            SapConnectField sapConnectField = sapConnectFieldMapper.selectOne(new QueryWrapper<SapConnectField>().eq("connect_id", confConnect.getId()));
//                            if(null == sapConnectField){
//                                throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的sap连接：【"+confConnect.getName()+"】的输入参数存在异常，请检查！");
//                            }
//                            sapConnectFieldInfo.setId(sapConnectField.getId());
//                            sapConnectFieldInfo.setConnectId(confConnect.getId());
//                        }
//                    }
//                    if(Objects.equals(newJobNodeInfo.getTypeId(),JobType.SQL.getCode())){
//                        //输出表设置
//                        List<String> jobOutPutTableIds = jobNodeConfig.getJobOutPutTableIds();
//                        if(CollectionUtil.isNotEmpty(jobOutPutTableIds)){
//                            List<String> jobOutPutTableNames = jobNodeConfig.getJobOutPutTableNames();
//                            List<String> newJobOutPutTableIds = new ArrayList<>();
//                            for(int i = 0; i < jobOutPutTableIds.size(); i++){
//                                String s = jobOutPutTableNames.get(i);
//                                if(StringUtils.isNotEmpty(s)){
//                                    String[] split = s.split("\\.");
//                                    TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
//                                    if(null != tableInfo){
//                                        newJobOutPutTableIds.add(tableInfo.getId().toString());
//                                    }
//                                }
//                            }
//                            jobNodeConfig.setJobOutPutTableIds(newJobOutPutTableIds);
//                        }
//
//                    }
//                    if(Objects.equals(newJobNodeInfo.getTypeId(),JobType.OUTPUT.getCode())){
//                        //输出的连接id
//                        List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
//                        if(CollectionUtil.isEmpty(connectList)){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getOutput_connect_id()+"】不存在！");
//                        }
//                        ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getOutput_connect_id(), o.getId())).findAny().orElse(null);
//                        if(null == confConnectAndConfigDto){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getOutput_connect_id()+"】不存在！");
//                        }
//                        Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
//                        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>().eq("name", confConnectAndConfigDto.getName()).eq("create_per",userId));
//                        if(null == confConnect){
//                            throw new RRException("节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnectAndConfigDto.getName()+"】不存在！");
//                        }
//                        jobNodeConfig.setOutput_connect_id(confConnect.getId());
//                    }
//
//                    newJobNodeInfo.setJobNodeConfig(jobNodeConfig);
//                    jobNodeInfoService.saveJobNodeConfig(newJobNodeInfo);
//                }
//
//                newJobNodeInfos.add(newJobNodeInfo);
//            }
//        }
//        //对应节点的依赖路由配置
//        if(null != jobInfoDto && CollectionUtil.isNotEmpty(jobInfoDto.getJobNodeInfos())){
//            List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
//            for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
//                List<JobNodeLayConfigDto> jobNodeLayConfigDtoList = jobNodeInfo.getJobNodeLayConfigDtoList();
//                if(CollectionUtil.isNotEmpty(jobNodeLayConfigDtoList)){
//                    JobNodeLayConfigDto jobNodeLayConfigDto = jobNodeLayConfigDtoList.get(0);
//                    if(null != jobNodeLayConfigDto.getOutputTableId()){
//                        List<JobNodeLayConfigDto> newJobNodeLayConfigDtoList = new ArrayList<>();
//                        JobNodeLayConfigDto jobNodeLayConfigDto1 = new JobNodeLayConfigDto();
//                        BeanUtils.copyProperties(jobNodeLayConfigDto,jobNodeLayConfigDto1);
//                        jobNodeLayConfigDto1.setJobId(jobNodeInfo.getNewJobId());
//                        JobNodeInfo upJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeLayConfigDto.getUpNodeId())).findAny().orElse(null);
//                        JobNodeInfo currentJobNodeInfo = jobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeLayConfigDto.getCurrentNodeId())).findAny().orElse(null);
//                        if(null == upJobNodeInfo || null == currentJobNodeInfo){
//                            throw new RRException("当前：【"+jobNodeLayConfigDto.getCurrentNodeId()+"】或者上级节点：【"+jobNodeLayConfigDto.getUpNodeId()+"】不存在！");
//                        }
//                        jobNodeLayConfigDto1.setUpNodeId(upJobNodeInfo.getId());
//                        jobNodeLayConfigDto1.setCurrentNodeId(currentJobNodeInfo.getId());
//                        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", jobNodeLayConfigDto.getDbName()).eq("table_name", jobNodeLayConfigDto.getTableName()));
//                        if(null == tableInfo){
//                            throw new RRException("当前系统不存在仓库表：【"+jobNodeLayConfigDto.getDbName() + "." + jobNodeLayConfigDto.getTableName() + "】");
//                        }
//                        jobNodeLayConfigDto1.setOutputTableId(tableInfo.getId());
//                        jobNodeLayConfigDto1.setDutyUser(sysUserService.getUserId(jobNodeLayConfigDto.getDutyUserName(),ShiroUtils.getUserId().intValue()));
//                        //需要重新生成节点信息
//                        JobNodeInfo jobNodeInfo1 = newJobNodeInfos.stream().filter(o -> Objects.equals(o.getId(), jobNodeInfo.getNewId())).findAny().orElse(null);
//                        if(null != jobNodeInfo1){
//                            jobNodeInfo1.setJobNodeLayConfigDtoList(newJobNodeLayConfigDtoList);
//                            jobNodeInfoService.saveJobNodeConfig(jobNodeInfo1);
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//    /***
//     * 检查对应的上传的版本和当前的版本对应的资源数据的对比
//     * @param versionZipDto
//     * @return
//     */
//    private List<VersionStatusVO> cheackCurrentDataToVersionData(VersionZipDto versionZipDto,Integer procId) {
//        List<VersionStatusVO> restVersionList = new ArrayList<>();
//        //udf函数对比
//        if (CollectionUtil.isNotEmpty(versionZipDto.getUdfList())) {
//            for (JobRunUdfDto jobRunUdfDto : versionZipDto.getUdfList()) {
//                //暂时验证udf函数是否存在
//                JobRunUdf jobRunUdf = jobRunUdfMapper.selectOne(new QueryWrapper<JobRunUdf>().eq("jar_method_name", jobRunUdfDto.getJarMethodName()));
//                if (null == jobRunUdf) {
//                    restVersionList.add(pingVersionStatus(
//                            ErrorType.UDF.getCode(),
//                            ErrorType.UDF.getName(),
//                            "udf函数名字：【" + jobRunUdfDto.getJarMethodName() + "】不存在！",
//                            jobRunUdfDto.getJarMethodName(),
//                            1,
//                            null));
//                }
//            }
//        }
//        //数据源对比
//        if (CollectionUtil.isNotEmpty(versionZipDto.getConnectList())) {
//            for (ConfConnectAndConfigDto confConnectAndConfigDto : versionZipDto.getConnectList()) {
//                //验证数据源连接是否存在
//                Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
//                ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>().eq("name", confConnectAndConfigDto.getName()).eq("create_per",userId));
//                if(null == confConnect){
//                    restVersionList.add(pingVersionStatus(
//                            ErrorType.CONNECT.getCode(),
//                            ErrorType.CONNECT.getName(),
//                            "数据源连接的名字：【" + confConnectAndConfigDto.getName() + "】不存在！",
//                            confConnectAndConfigDto.getName(),
//                            1,
//                            confConnectAndConfigDto.getCreatePerName()));
//                    continue;
//                }
//                //验证数据源连接是否已关联
//                List<ProcConnect> procConnects = procConnectMapper.selectList(new QueryWrapper<ProcConnect>()
//                        .eq("proc_id", procId)
//                        .eq("connect_id", confConnect.getId()));
//                if(CollectionUtil.isEmpty(procConnects)){
//                    restVersionList.add(pingVersionStatus(
//                            ErrorType.CONNECT.getCode(),
//                            ErrorType.CONNECT.getName(),
//                            "数据源连接的名字：【" + confConnectAndConfigDto.getName() + "】未关联到项目！",
//                            confConnectAndConfigDto.getName(),
//                            1,
//                            confConnectAndConfigDto.getCreatePerName()));
//                }
//                //验证数据源连接的配置数据
//                VersionStatusVO versionStatusVO = cheackConnectDatas(confConnectAndConfigDto,confConnect);
//                if(null != versionStatusVO){
//                    restVersionList.add(versionStatusVO);
//                }
//            }
//        }
//        //数据仓库对比
//        if(CollectionUtil.isNotEmpty(versionZipDto.getTableList())){
//            for (TableInfoAndFieldDto tableInfoAndFieldDto : versionZipDto.getTableList()) {
//                //检验仓库是否存在
//                TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>()
//                        .eq("db_name", tableInfoAndFieldDto.getDbName())
//                        .eq("table_name", tableInfoAndFieldDto.getTableName()));
//                if(null == tableInfo){
//                    restVersionList.add(pingVersionStatus(
//                            ErrorType.TABLE.getCode(),
//                            ErrorType.TABLE.getName(),
//                            "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】不存在！",
//                            tableInfoAndFieldDto.getTableName(),
//                            1,
//                            tableInfoAndFieldDto.getCreatePerName()));
//                    continue;
//                }
//                //检验仓库是否被关联到数据源
//                List<ProcTable> procTables = procTableMapper.selectList(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
//                if(CollectionUtil.isEmpty(procTables)){
//                    restVersionList.add(pingVersionStatus(
//                            ErrorType.TABLE.getCode(),
//                            ErrorType.TABLE.getName(),
//                            "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】未关联到当前项目！",
//                            tableInfoAndFieldDto.getTableName(),
//                            1,
//                            tableInfoAndFieldDto.getCreatePerName()));
//                }
//                //检查仓库表对应的字段是否匹配
//                List<TableFieldInfo> tableFieldInfos = tableFieldInfoMapper.selectList(new QueryWrapper<TableFieldInfo>().eq("table_id", tableInfo.getId()));
//                List<TableFieldInfo> tableFieldInfos1 = tableInfoAndFieldDto.getTableFieldInfos();
//                if(CollectionUtil.isNotEmpty(tableFieldInfos1)){
//                    if(CollectionUtil.isEmpty(tableFieldInfos)){
//                        restVersionList.add(pingVersionStatus(
//                                ErrorType.TABLE.getCode(),
//                                ErrorType.TABLE.getName(),
//                                "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】无字段，不匹配，请重新建！",
//                                tableInfoAndFieldDto.getTableName(),
//                                1,
//                                tableInfoAndFieldDto.getCreatePerName()));
//                    }else{
//                        Map<String, List<TableFieldInfo>> collect = tableFieldInfos.stream().collect(Collectors.groupingBy(TableFieldInfo::getFieldName));
//                        for (TableFieldInfo tableFieldInfo : tableFieldInfos1) {
//                            if(!collect.keySet().contains(tableFieldInfo.getFieldName())){
//                                restVersionList.add(pingVersionStatus(
//                                        ErrorType.TABLE.getCode(),
//                                        ErrorType.TABLE.getName(),
//                                        "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】无字段：【"+tableFieldInfo.getFieldName()+"】，请重新建！",
//                                        tableInfoAndFieldDto.getTableName(),
//                                        1,
//                                        tableInfoAndFieldDto.getCreatePerName()));
//                            }else{
//                                //验证字段类型
//                                List<TableFieldInfo> tableFieldInfos2 = collect.get(tableFieldInfo.getFieldName());
//                                if(CollectionUtil.isEmpty(tableFieldInfos2)){
//                                    restVersionList.add(pingVersionStatus(
//                                            ErrorType.TABLE.getCode(),
//                                            ErrorType.TABLE.getName(),
//                                            "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】无字段：【"+tableFieldInfo.getFieldName()+"】，请重新建！",
//                                            tableInfoAndFieldDto.getTableName(),
//                                            1,
//                                            tableInfoAndFieldDto.getCreatePerName()));
//                                }else{
//                                    if(!Objects.equals(tableFieldInfo.getFieldType(),tableFieldInfos2.get(0).getFieldType())){
//                                        restVersionList.add(pingVersionStatus(
//                                                ErrorType.TABLE.getCode(),
//                                                ErrorType.TABLE.getName(),
//                                                "数据仓库表名：【" + tableInfoAndFieldDto.getTableName() + "】中字段：【"+tableFieldInfo.getFieldName()+"】的类型不匹配，版本包仓库表字段类型：【"+tableFieldInfo.getFieldType()+"】，本系统仓库表字段类型：【"+tableFieldInfos2.get(0).getFieldType()+"】，请重新建！",
//                                                tableInfoAndFieldDto.getTableName(),
//                                                1,
//                                                tableInfoAndFieldDto.getCreatePerName()));
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
//
//        //工作流和工作流依赖对比
//        if(CollectionUtil.isNotEmpty(versionZipDto.getWorkMenuList())){
//            //查询到当前工程下对应的菜单
//            List<WorkMenu> newWorkMenus = workMenuMapper.selectList(new QueryWrapper<WorkMenu>().eq("proc_id", procId));
//            Map<Long, List<WorkMenuAndLayDto>> olderWorkMenuMaps = versionZipDto.getWorkMenuList().stream().collect(Collectors.groupingBy(WorkMenuAndLayDto::getRootId));
//            //按照根菜单进行名字查找看是否存在。当前工程下
//            for(Map.Entry<Long, List<WorkMenuAndLayDto>> entry : olderWorkMenuMaps.entrySet()){
//                List<WorkMenuAndLayDto> rootWorkMenus = entry.getValue();
//                if(CollectionUtil.isNotEmpty(rootWorkMenus)){
//                    if(CollectionUtil.isNotEmpty(newWorkMenus)){
//                        //验证重名
//                        cheackDoubleNameInistVersionList(entry,newWorkMenus,restVersionList);
//                    }
//                    //验证工作流的数据仓库和数据源
//                    cheackTableAndConnect(versionZipDto, entry,restVersionList,procId);
//                }
//            }
//        }
//
//        return restVersionList;
//    }
//
//    private VersionStatusVO pingVersionStatus(int errorCode, String errorName, String errorMsg, String name, int errorNeedType, String createName) {
//        VersionStatusVO versionStatusVO = new VersionStatusVO();
//        versionStatusVO.setErrorType(errorCode);
//        if(StringUtils.isNotEmpty(errorName) && StringUtils.isNotEmpty(errorMsg)){
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.put(errorName, errorMsg);
//            versionStatusVO.setErrorObjs(jsonObject);
//        }
//        versionStatusVO.setErrorNeedType(errorNeedType);
//        versionStatusVO.setName(name);
//        versionStatusVO.setCreateName(createName);
//        return versionStatusVO;
//    }
//
//    private void cheackTableAndConnect(VersionZipDto versionZipDto, Map.Entry<Long, List<WorkMenuAndLayDto>> entry, List<VersionStatusVO> restVersionList, Integer procId) {
//        if(null != entry){
//            Long olderRootId = entry.getKey();
//            List<WorkMenuAndLayDto> olderWorkMenus = entry.getValue();
//            if(null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)){
//                WorkMenuAndLayDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
//                if(null != workMenuAndLayDto){
//                    StringBuffer sbWorkMenuName = new StringBuffer();
//                    List<WorkMenuAndLayDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
//                    sbWorkMenuName.append(workMenuAndLayDto.getName());
//                    initTableAndConnectError(versionZipDto,olderChildrens,olderWorkMenus,restVersionList,sbWorkMenuName,procId);
//                }
//            }
//        }
//    }
//
//    private void initTableAndConnectError(VersionZipDto versionZipDto, List<WorkMenuAndLayDto> olderChildrens, List<WorkMenuAndLayDto> olderWorkMenus, List<VersionStatusVO> restVersionList, StringBuffer sbWorkMenuName, Integer procId) {
//        if(CollectionUtil.isNotEmpty(olderChildrens)){
//            for (WorkMenuAndLayDto olderChildren : olderChildrens) {
//                StringBuffer olderTemp = new StringBuffer(sbWorkMenuName);
//                StringBuffer newTemp = olderTemp.append("/").append(olderChildren.getName());
//                if(Objects.equals(olderChildren.getWorkType(),WorkFlowMenuType.WORKFLOW_FIELD.getCode())){
//                    //验证数据仓库和数据源
//                    JobInfoDto jobInfoDto = olderChildren.getJobInfoDto();
//                    if(null != jobInfoDto){
//                        List<JobNodeInfo> jobNodeInfos = jobInfoDto.getJobNodeInfos();
//                        if(CollectionUtil.isNotEmpty(jobNodeInfos)){
//                            for (JobNodeInfo jobNodeInfo : jobNodeInfos) {
//                                JobNodeConfig jobNodeConfig = jobNodeInfo.getJobNodeConfig();
//                                if(null != jobNodeConfig){
//                                    if(Objects.equals(jobNodeInfo.getTypeId(), JobType.INPUT.getCode())){
//                                        //连接id
//                                        List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
//                                        if(CollectionUtil.isEmpty(connectList)){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getInput_connect_id()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                            continue;
//                                        }
//                                        ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getInput_connect_id(), o.getId())).findAny().orElse(null);
//                                        if(null == confConnectAndConfigDto){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getInput_connect_id()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                            continue;
//                                        }
//                                        Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
//                                        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>().eq("name", confConnectAndConfigDto.getName()).eq("create_per",userId).eq("type_id",confConnectAndConfigDto.getTypeId()));
//                                        if(null == confConnect){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnectAndConfigDto.getName()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                            continue;
//                                        }else{
//                                            //数据源连接是否已经关联
//                                            ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()));
//                                            if(null == procConnect){
//                                                restVersionList.add(pingVersionStatus(
//                                                        ErrorType.WORKFLOW.getCode(),
//                                                        ErrorType.WORKFLOW.getName(),
//                                                        "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnect.getName()+"】未关联到项目！",
//                                                        newTemp.toString(),
//                                                        1,
//                                                        olderChildren.getCreatePerName()));
//                                            }
//                                        }
//                                        if(Objects.equals(confConnect.getTypeId(), ConnectTypeEnum.Sap.getCode())){
//                                            //bdp_sap_connect_field 需要改变id
//                                            SapConnectField sapConnectField = sapConnectFieldMapper.selectOne(new QueryWrapper<SapConnectField>().eq("connect_id", confConnect.getId()));
//                                            if(null == sapConnectField){
//                                                restVersionList.add(pingVersionStatus(
//                                                        ErrorType.WORKFLOW.getCode(),
//                                                        ErrorType.WORKFLOW.getName(),
//                                                        "节点：【"+jobNodeInfo.getName()+"】里的sap连接：【"+confConnect.getName()+"】输入参数异常,请检查！",
//                                                        newTemp.toString(),
//                                                        1,
//                                                        olderChildren.getCreatePerName()));
//                                            }
//                                            //验证其sap的仓库表是否存在
//                                            List<String> sap_output_table_name = jobNodeConfig.getSap_output_table_name();
//                                            if(CollectionUtil.isNotEmpty(sap_output_table_name)){
//                                                for (String s : sap_output_table_name) {
//                                                    String[] split = s.split("\\.");
//                                                    if(split.length > 1){
//                                                        TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
//                                                        if(null == tableInfo){
//                                                            restVersionList.add(pingVersionStatus(
//                                                                    ErrorType.WORKFLOW.getCode(),
//                                                                    ErrorType.WORKFLOW.getName(),
//                                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据仓库：【"+s+"】不存在！",
//                                                                    newTemp.toString(),
//                                                                    1,
//                                                                    olderChildren.getCreatePerName()));
//                                                        }else{
//                                                            ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
//                                                            if(null == procTable){
//                                                                restVersionList.add(pingVersionStatus(
//                                                                        ErrorType.WORKFLOW.getCode(),
//                                                                        ErrorType.WORKFLOW.getName(),
//                                                                        "节点：【"+jobNodeInfo.getName()+"】里的数据仓库：【"+tableInfo.getDbName()+"."+tableInfo.getTableName()+"】未关联到项目！",
//                                                                        newTemp.toString(),
//                                                                        1,
//                                                                        olderChildren.getCreatePerName()));
//                                                            }
//                                                        }
//                                                    }
//                                                }
//                                            }
//
//                                        }
//                                        //对应的输出仓库的是否存在和是否关联到当前这个工程
//                                        if(StringUtils.isNotEmpty(jobNodeConfig.getOutput_db_name()) && StringUtils.isNotEmpty(jobNodeConfig.getOutput_table_name())){
//                                            TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", jobNodeConfig.getOutput_db_name()).eq("table_name", jobNodeConfig.getOutput_table_name()));
//                                            if(null == tableInfo){
//                                                restVersionList.add(pingVersionStatus(
//                                                        ErrorType.WORKFLOW.getCode(),
//                                                        ErrorType.WORKFLOW.getName(),
//                                                        "节点：【"+jobNodeInfo.getName()+"】里的数据仓库表：【"+jobNodeConfig.getOutput_db_name() + "." + jobNodeConfig.getOutput_table_name() +"】不存在！",
//                                                        newTemp.toString(),
//                                                        1,
//                                                        olderChildren.getCreatePerName()));
//                                            }else{
//                                                ProcTable procTable = procTableMapper.selectOne(new QueryWrapper<ProcTable>().eq("proc_id", procId).eq("table_id", tableInfo.getId()));
//                                                if(null == procTable){
//                                                    restVersionList.add(pingVersionStatus(
//                                                            ErrorType.WORKFLOW.getCode(),
//                                                            ErrorType.WORKFLOW.getName(),
//                                                            "节点：【"+jobNodeInfo.getName()+"】里的数据仓库：【"+tableInfo.getDbName()+"."+tableInfo.getTableName()+"】未关联到项目！",
//                                                            newTemp.toString(),
//                                                            1,
//                                                            olderChildren.getCreatePerName()));
//                                                }
//                                            }
//                                        }
//
//                                    }
//                                    if(Objects.equals(jobNodeInfo.getTypeId(),JobType.SQL.getCode())){
//                                        //输出表设置
//                                        List<String> jobOutPutTableIds = jobNodeConfig.getJobOutPutTableIds();
//                                        if(CollectionUtil.isNotEmpty(jobOutPutTableIds)){
//                                            List<String> jobOutPutTableNames = jobNodeConfig.getJobOutPutTableNames();
//                                            for(int i = 0; i < jobOutPutTableIds.size(); i++){
//                                                String s = jobOutPutTableNames.get(i);
//                                                if(StringUtils.isNotEmpty(s)){
//                                                    String[] split = s.split("\\.");
//                                                    TableInfo tableInfo = tableInfoMapper.selectOne(new QueryWrapper<TableInfo>().eq("db_name", split[0].trim()).eq("table_name", split[1].trim()));
//                                                    if(null == tableInfo){
//                                                        restVersionList.add(pingVersionStatus(
//                                                                ErrorType.WORKFLOW.getCode(),
//                                                                ErrorType.WORKFLOW.getName(),
//                                                                "节点：【"+jobNodeInfo.getName()+"】里的数据仓库：【"+s+"】不存在！",
//                                                                newTemp.toString(),
//                                                                1,
//                                                                olderChildren.getCreatePerName()));
//                                                    }
//                                                }
//                                            }
//                                        }
//                                    }
//                                    if(Objects.equals(jobNodeInfo.getTypeId(),JobType.OUTPUT.getCode())){
//                                        //输出的连接id
//                                        //连接id
//                                        List<ConfConnectAndConfigDto> connectList = versionZipDto.getAllConnectList();
//                                        if(CollectionUtil.isEmpty(connectList)){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getOutput_connect_id()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                            continue;
//                                        }
//                                        ConfConnectAndConfigDto confConnectAndConfigDto = connectList.stream().filter(o -> Objects.equals(jobNodeConfig.getOutput_connect_id(), o.getId())).findAny().orElse(null);
//                                        if(null == confConnectAndConfigDto){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+jobNodeConfig.getOutput_connect_id()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                            continue;
//                                        }
//                                        Integer userId = sysUserService.getUserId(confConnectAndConfigDto.getCreatePerName(), ShiroUtils.getUserId().intValue());
//                                        ConfConnect confConnect = confConnectMapper.selectOne(new QueryWrapper<ConfConnect>().eq("name", confConnectAndConfigDto.getName()).eq("create_per",userId));
//                                        if(null == confConnect){
//                                            restVersionList.add(pingVersionStatus(
//                                                    ErrorType.WORKFLOW.getCode(),
//                                                    ErrorType.WORKFLOW.getName(),
//                                                    "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnectAndConfigDto.getName()+"】不存在！",
//                                                    newTemp.toString(),
//                                                    1,
//                                                    olderChildren.getCreatePerName()));
//                                        }else{
//                                            //数据源连接是否已经关联
//                                            ProcConnect procConnect = procConnectMapper.selectOne(new QueryWrapper<ProcConnect>().eq("proc_id", procId).eq("connect_id", confConnect.getId()));
//                                            if(null == procConnect){
//                                                restVersionList.add(pingVersionStatus(
//                                                        ErrorType.WORKFLOW.getCode(),
//                                                        ErrorType.WORKFLOW.getName(),
//                                                        "节点：【"+jobNodeInfo.getName()+"】里的数据源连接：【"+confConnect.getName()+"】未关联到项目！",
//                                                        newTemp.toString(),
//                                                        1,
//                                                        olderChildren.getCreatePerName()));
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }else{
//                    //继续递归
//                    List<WorkMenuAndLayDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
//                    initTableAndConnectError(versionZipDto, olderChildrens1,olderWorkMenus,restVersionList,newTemp, procId);
//                }
//            }
//        }
//    }
//
//    private void cheackDoubleNameInistVersionList(Map.Entry<Long, List<WorkMenuAndLayDto>> entry, List<WorkMenu> newWorkMenus, List<VersionStatusVO> restVersionList) {
//        if(null != entry){
//            Long olderRootId = entry.getKey();
//            List<WorkMenuAndLayDto> olderWorkMenus = entry.getValue();
//            if(null != olderRootId && CollectionUtil.isNotEmpty(olderWorkMenus)){
//                WorkMenuAndLayDto workMenuAndLayDto = olderWorkMenus.stream().filter(o -> Objects.equals(o.getId(), olderRootId)).findAny().orElse(null);
//                if(null != workMenuAndLayDto){
//                    WorkMenu workMenu1 = newWorkMenus.stream().filter(workMenu -> {
//                        if (Objects.equals(workMenu.getParentId(), 0L) && Objects.equals(workMenu.getName(), workMenuAndLayDto.getName())) {
//                            return true;
//                        }
//                        return false;
//                    }).findAny().orElse(null);
//                    //有重名的根目录
//                    if(null != workMenu1){
//                        StringBuffer sbWorkMenuName = new StringBuffer();
//                        sbWorkMenuName.append(workMenu1.getName());
//                        restVersionList.add(pingVersionStatus(
//                                ErrorType.WORKFLOW.getCode(),
//                                ErrorType.WORKFLOW.getName(),
//                                "菜单根目录：【" + workMenu1.getName() + "】在当前工程中有重复的！",
//                                sbWorkMenuName.toString(),
//                                2,
//                                workMenuAndLayDto.getCreatePerName()));
//
//                        List<WorkMenuAndLayDto> olderChildrens = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), workMenuAndLayDto.getId())).collect(Collectors.toList());
//                        List<WorkMenu> newChildrens = newWorkMenus.stream().filter(workMenu -> Objects.equals(workMenu1.getId(), workMenu.getParentId())).collect(Collectors.toList());
//                        //遍历下面的菜单
//                        initErrorData(olderChildrens,newChildrens,olderWorkMenus,newWorkMenus,restVersionList,sbWorkMenuName);
//                    }
//                }
//            }
//        }
//    }
//
//    private void initErrorData(List<WorkMenuAndLayDto> olderChildrens, List<WorkMenu> newChildrens,
//                               List<WorkMenuAndLayDto> olderWorkMenus, List<WorkMenu> newWorkMenus,
//                               List<VersionStatusVO> restVersionList, StringBuffer sbWorkMenuName) {
//        if(CollectionUtil.isNotEmpty(newChildrens) && CollectionUtil.isNotEmpty(olderChildrens)){
//            for (WorkMenuAndLayDto olderChildren : olderChildrens) {
//                StringBuffer olderTemp = new StringBuffer(sbWorkMenuName);
//                StringBuffer newTemp = olderTemp.append("/").append(olderChildren.getName());
//                WorkMenu workMenu = newChildrens.stream().filter(o -> Objects.equals(o.getName(), olderChildren.getName())).findAny().orElse(null);
//                if(null != workMenu){
//                    if(Objects.equals(workMenu.getWorkType(),WorkFlowMenuType.WORKFLOW_FIELD.getCode())){
//                        restVersionList.add(pingVersionStatus(
//                                ErrorType.WORKFLOW.getCode(),
//                                ErrorType.WORKFLOW.getName(),
//                                "菜单目录：【" + workMenu.getName() + "】在当前工程中有重复的！",
//                                newTemp.toString(),
//                                2,
//                                workMenu.getCreatePerName()));
//                    }else{
//                        restVersionList.add(pingVersionStatus(
//                                ErrorType.WORKFLOW.getCode(),
//                                ErrorType.WORKFLOW.getName(),
//                                "菜单目录：【" + workMenu.getName() + "】在当前工程中有重复的！",
//                                newTemp.toString(),
//                                2,
//                                workMenu.getCreatePerName()));
//                    }
//
//                    List<WorkMenuAndLayDto> olderChildrens1 = olderWorkMenus.stream().filter(workMenuAndLayDto1 -> Objects.equals(workMenuAndLayDto1.getParentId(), olderChildren.getId())).collect(Collectors.toList());
//                    List<WorkMenu> newChildrens1 = newWorkMenus.stream().filter(workMenu1 -> Objects.equals(workMenu.getId(), workMenu1.getParentId())).collect(Collectors.toList());
//                    //遍历下面的菜单
//                    initErrorData(olderChildrens1,newChildrens1,olderWorkMenus,newWorkMenus,restVersionList, newTemp);
//                }
//            }
//        }
//    }
//
//    private VersionStatusVO cheackConnectDatas(ConfConnectAndConfigDto confConnectAndConfigDto, ConfConnect confConnect) {
//        //数据源连接类型
//        if(Objects.equals(confConnect.getTypeId(),confConnectAndConfigDto.getTypeId())){
//            return pingVersionStatus(
//                    ErrorType.CONNECT.getCode(),
//                    ErrorType.CONNECT.getName(),
//                    "数据源连接的名字：【" + confConnectAndConfigDto.getName() + "】和本系统的数据源连接类型不一致！",
//                    confConnectAndConfigDto.getName(),
//                    1,
//                    confConnectAndConfigDto.getCreatePerName());
//        }
//        //TODO:hujz 其类型对应的配置的数据进行对比
//
//        return null;
//    }

}
